Title: | Dynamic 'R' Prompt |
---|---|
Description: | Set the 'R' prompt dynamically, from a function. The package contains some examples to include various useful dynamic information in the prompt: the status of the last command (success or failure); the amount of memory allocated by the current 'R' process; the name of the R package(s) loaded by 'pkgload' and/or 'devtools'; various 'git' information: the name of the active branch, whether it is dirty, if it needs pushes pulls. You can also create your own prompt if you don't like the predefined examples. |
Authors: | Gábor Csárdi |
Maintainer: | Gábor Csárdi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.2.9000 |
Built: | 2024-11-23 03:01:41 UTC |
Source: | https://github.com/gaborcsardi/prompt |
It is inspired by the https://github.com/powerline/powerline project. This prompt uses some Unicode glyphs that work best with the fonts specifically modified for Powerline: https://github.com/powerline/fonts It also works best on consoles that support ANSI colors.
new_prompt_powerline( parts = list("status", "memory", "loadavg", "path", "devtools", "git"), colors = powerline_colors(parts) )
new_prompt_powerline( parts = list("status", "memory", "loadavg", "path", "devtools", "git"), colors = powerline_colors(parts) )
parts |
List of strings and functions. Strings are for the
built-in powerline pieces, functions are arbitrary functions with
four parameters:
|
colors |
Colors of the parts. Builtin parts have default colors, but you can change them. |
make_prompt_powerline()
returns a function that you can
use with set_prompt()
.
Other example prompts:
prompt_devtools()
,
prompt_fancy()
,
prompt_git()
,
prompt_mem()
,
prompt_runtime()
,
prompt_status()
If git is installed and the current directory is part of a git tree,
then also shows all information from prompt_git
.
prompt_devtools(...) devtools_packages()
prompt_devtools(...) devtools_packages()
... |
Ignored. |
prompt_devtools()
returns the prompt string.
devtools_packages()
returns the packages loaded by
devtools/pkgload.
Other example prompts:
new_prompt_powerline()
,
prompt_fancy()
,
prompt_git()
,
prompt_mem()
,
prompt_runtime()
,
prompt_status()
It also uses color, on terminals that support it. Is shows:
Status of last command.
Memory usage of the R process.
Load average of the machine.
Package being developed using devtools, if any.
Git branch and state of the working tree if within a git tree.
prompt_fancy(expr, value, ok, visible)
prompt_fancy(expr, value, ok, visible)
expr |
Evaluated expression. |
value |
Its value. |
ok |
Whether the evaluation succeeded. |
visible |
Whether the result is visible. |
prompt_fancy()
returns the prompt string.
Other example prompts:
new_prompt_powerline()
,
prompt_devtools()
,
prompt_git()
,
prompt_mem()
,
prompt_runtime()
,
prompt_status()
An example 'git' prompt
prompt_git(...) is_git_dir() git_branch() git_arrows() git_remote_status() git_dirty()
prompt_git(...) is_git_dir() git_branch() git_arrows() git_remote_status() git_dirty()
... |
Unused. |
prompt_git()
is a prompt with information about the git repository
in the current working directory. It shows the current branch, whether
there are commits to push or pull to the default remote, and whether
the working directory is dirty.
is_git_dir()
checks whether the working directory is in a git tree.
If git is not installed, then it always returns FALSE
.
git_branch()
returns the name of the current branch.
git_arrows()
checks the status of the local tree compared to the
configured remote.
git_remote_status()
checks the status of the local tree, compared to
a configured remote.
git_dirty()
checks if the local tree has uncommitted changes.
If there are, it returns "*"
. Note that it also returns "*"
on a
git error, so you might want to use is_git_dir()
as well.
prompt_git()
returns the prompt as a string.
is_git_dir()
returns a logical scalar.
git_branch()
returns a string. If the repository has no commits, then
it returns "main"
. Note that if git is not available, or fails for
any reason, it will also return "main"
, so you might want to call
is_git_dir()
as well.
git_arrows()
returns a string that has a down arrow if the remote
has extra commits, and a down arrow if the local tree has extra commits
compared to the remote. Or both arrows for diverged branches. If it is
not the empty string then it adds a leading space character.
git_remote_status()
returns a numeric vector of length two. The first
number is the number of extra commits in the local tree. The second
number is the number of extra commits in the remote. If there is no
remote, or git errors, it returns a vector of two NA
s.
git_dirty()
returns a character string, "*"
or ""
.
Other example prompts:
new_prompt_powerline()
,
prompt_devtools()
,
prompt_fancy()
,
prompt_mem()
,
prompt_runtime()
,
prompt_status()
Example prompt that shows the current memory usage of the R process
prompt_mem(...) memory_usage()
prompt_mem(...) memory_usage()
... |
Ignored. |
prompt_mem()
is a simple example prompt that shows the physical memory
allocated by the current process.
memory_usage()
is a utility function that shows memory information
about the current R process and the system. You can use it to create a
custom prompt.
prompt_mem()
returns the formatted prompt in a string.
memory_usage()
returns a list with entries:
bytes
: the number of bytes of memory the current process uses.
This is the 'Resident Set Size', see ps::ps_memory_info()
.
formatted
: string that formats bytes
nicely, with the appropriate
unit.
total
: Total physical memory. See ps::ps_system_memory()
.
avail
: the memory that can be given instantly to processes
without the system going into swap. See ps::ps_system_memory()
.
percent
: Percentage of memory that is taken. See
ps::ps_system_memory()
.
Other example prompts:
new_prompt_powerline()
,
prompt_devtools()
,
prompt_fancy()
,
prompt_git()
,
prompt_runtime()
,
prompt_status()
cat(prompt_mem()) memory_usage()
cat(prompt_mem()) memory_usage()
A prompt that shows the CPU time used by the last top level expression
prompt_runtime(...)
prompt_runtime(...)
... |
Arguments, ignored. |
The prompt. '
Other example prompts:
new_prompt_powerline()
,
prompt_devtools()
,
prompt_fancy()
,
prompt_git()
,
prompt_mem()
,
prompt_status()
A prompt that shows the status (OK or error) of the last expression
prompt_status(expr, value, ok, visible)
prompt_status(expr, value, ok, visible)
expr |
Evaluated expression. |
value |
Its value. |
ok |
Whether the evaluation succeeded. |
visible |
Whether the result is visible. |
prompt_status()
returns the prompt string.
Other example prompts:
new_prompt_powerline()
,
prompt_devtools()
,
prompt_fancy()
,
prompt_git()
,
prompt_mem()
,
prompt_runtime()
Set and control the prompt
set_prompt(value) suspend() restore() toggle()
set_prompt(value) suspend() restore() toggle()
value |
A character string for a static prompt, or a function that is called after the evaluation every expression typed at the R prompt. The function should always return a character scalar. |
Function update_prompt()
is used to replace the default R
prompt with a custom prompt. A custom prompt can be disabled
with suspend()
and then re-enable with restore()
.
Function toggle()
toggles between the two.
No return value, called for side effects.