Refactor functions and update documentation
Add new variable to enable/disable git prompt minimal status information and consolidate functions for code re-use. Also update README documentation to capture the usage of new variable.pull/874/head
parent
a068e3b66e
commit
1d55249181
14
README.md
14
README.md
|
|
@ -200,6 +200,8 @@ Set `SCM_GIT_SHOW_DETAILS` to 'false' to **don't show** it:
|
||||||
|
|
||||||
* `export SCM_GIT_SHOW_DETAILS=false`
|
* `export SCM_GIT_SHOW_DETAILS=false`
|
||||||
|
|
||||||
|
**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_DETAILS` is ignored.
|
||||||
|
|
||||||
#### Remotes and remote branches
|
#### Remotes and remote branches
|
||||||
|
|
||||||
In some git workflows you must work with various remotes, for this reason, Bash-it can provide some useful information about your remotes and your remote branches, for example, the remote on you are working, or if your local branch is tracking a remote branch.
|
In some git workflows you must work with various remotes, for this reason, Bash-it can provide some useful information about your remotes and your remote branches, for example, the remote on you are working, or if your local branch is tracking a remote branch.
|
||||||
|
|
@ -218,6 +220,8 @@ Set `SCM_GIT_SHOW_REMOTE_INFO` to 'false' to **disable the feature**:
|
||||||
|
|
||||||
* `export SCM_GIT_SHOW_REMOTE_INFO=false`
|
* `export SCM_GIT_SHOW_REMOTE_INFO=false`
|
||||||
|
|
||||||
|
**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_REMOTE_INFO` is ignored.
|
||||||
|
|
||||||
#### Untracked files
|
#### Untracked files
|
||||||
|
|
||||||
By default, `git status` command shows information about *untracked* files, this behavior can be controlled through command line flags or git configuration files, for big repositories, ignoring *untracked* files can make git faster. Bash-it uses `git status` to gather the repo information it shows in the prompt, so in some circumstances, can be useful to instruct Bash-it to ignore these files. You can control this behavior with the flag `SCM_GIT_IGNORE_UNTRACKED`:
|
By default, `git status` command shows information about *untracked* files, this behavior can be controlled through command line flags or git configuration files, for big repositories, ignoring *untracked* files can make git faster. Bash-it uses `git status` to gather the repo information it shows in the prompt, so in some circumstances, can be useful to instruct Bash-it to ignore these files. You can control this behavior with the flag `SCM_GIT_IGNORE_UNTRACKED`:
|
||||||
|
|
@ -250,6 +254,16 @@ And
|
||||||
|
|
||||||
* `export SCM_THEME_CURRENT_USER_SUFFIX=' '``
|
* `export SCM_THEME_CURRENT_USER_SUFFIX=' '``
|
||||||
|
|
||||||
|
**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_CURRENT_USER` is ignored.
|
||||||
|
|
||||||
|
#### Git show minimal status info
|
||||||
|
|
||||||
|
To speed up the prompt while still getting minimal git status information displayed such as the value of HEAD and whether there are any dirty objects, you can set:
|
||||||
|
|
||||||
|
```
|
||||||
|
export SCM_GIT_SHOW_MINIMAL_INFO=true
|
||||||
|
```
|
||||||
|
|
||||||
#### Ignore repo status
|
#### Ignore repo status
|
||||||
|
|
||||||
When working in repos with a large code base Bash-it can slow down your prompt when checking the repo status, to avoid it, there is an option you can set via Git config to disable checking repo status in Bash-it.
|
When working in repos with a large code base Bash-it can slow down your prompt when checking the repo status, to avoid it, there is an option you can set via Git config to disable checking repo status in Bash-it.
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ SCM_GIT_SHOW_DETAILS=${SCM_GIT_SHOW_DETAILS:=true}
|
||||||
SCM_GIT_SHOW_REMOTE_INFO=${SCM_GIT_SHOW_REMOTE_INFO:=auto}
|
SCM_GIT_SHOW_REMOTE_INFO=${SCM_GIT_SHOW_REMOTE_INFO:=auto}
|
||||||
SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false}
|
SCM_GIT_IGNORE_UNTRACKED=${SCM_GIT_IGNORE_UNTRACKED:=false}
|
||||||
SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false}
|
SCM_GIT_SHOW_CURRENT_USER=${SCM_GIT_SHOW_CURRENT_USER:=false}
|
||||||
|
SCM_GIT_SHOW_MINIMAL_INFO=${SCM_GIT_SHOW_MINIMAL_INFO:=false}
|
||||||
|
|
||||||
SCM_GIT='git'
|
SCM_GIT='git'
|
||||||
SCM_GIT_CHAR='±'
|
SCM_GIT_CHAR='±'
|
||||||
|
|
@ -93,22 +94,24 @@ function scm_prompt_info {
|
||||||
scm_prompt_char
|
scm_prompt_char
|
||||||
SCM_DIRTY=0
|
SCM_DIRTY=0
|
||||||
SCM_STATE=''
|
SCM_STATE=''
|
||||||
[[ $SCM == $SCM_GIT ]] && git_prompt_info && return
|
|
||||||
[[ $SCM == $SCM_HG ]] && hg_prompt_info && return
|
if [[ ${SCM} == ${SCM_GIT} ]]; then
|
||||||
[[ $SCM == $SCM_SVN ]] && svn_prompt_info && return
|
if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then
|
||||||
|
# user requests minimal git status information
|
||||||
|
git_prompt_minimal_info
|
||||||
|
else
|
||||||
|
# more detailed git status
|
||||||
|
git_prompt_info
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# TODO: consider adding minimal status information for hg and svn
|
||||||
|
[[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return
|
||||||
|
[[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_status {
|
function git_prompt_minimal_info {
|
||||||
scm
|
|
||||||
scm_prompt_char
|
|
||||||
SCM_DIRTY=0
|
|
||||||
SCM_STATE=''
|
|
||||||
[[ $SCM == $SCM_GIT ]] && git_prompt_status && return
|
|
||||||
[[ $SCM == $SCM_HG ]] && hg_prompt_info && return
|
|
||||||
[[ $SCM == $SCM_SVN ]] && svn_prompt_info && return
|
|
||||||
}
|
|
||||||
|
|
||||||
function git_prompt_status {
|
|
||||||
local ref
|
local ref
|
||||||
local status
|
local status
|
||||||
local git_status_flags=('--porcelain')
|
local git_status_flags=('--porcelain')
|
||||||
|
|
@ -117,7 +120,7 @@ function git_prompt_status {
|
||||||
if [[ "$(command git config --get bash-it.hide-status)" != "1" ]]; then
|
if [[ "$(command git config --get bash-it.hide-status)" != "1" ]]; then
|
||||||
# Get the branch reference
|
# Get the branch reference
|
||||||
ref=$(command git symbolic-ref -q HEAD 2> /dev/null) || \
|
ref=$(command git symbolic-ref -q HEAD 2> /dev/null) || \
|
||||||
ref=$(command git rev-parse --short HEAD 2> /dev/null)
|
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
|
||||||
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref#refs/heads/}
|
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref#refs/heads/}
|
||||||
|
|
||||||
# Get the status
|
# Get the status
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue