prompt (version 1.0.0)

prompt_git: An example 'git' prompt

Description

An example 'git' prompt

Usage

prompt_git(...)

is_git_dir()

git_branch()

git_arrows()

git_remote_status()

git_dirty()

Arguments

...

Unused.

Value

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 NAs.

git_dirty() returns a character string, "*" or "".

Details

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.

See Also

Other example prompts: new_prompt_powerline(), prompt_devtools(), prompt_fancy(), prompt_mem(), prompt_runtime(), prompt_status()

Examples

Run this code
# NOT RUN {
cat(prompt_git())
is_git_dir()
# }

Run the code above in your browser using DataCamp Workspace