mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
updates and cleanups to git prompt stuff
This commit is contained in:
parent
656919e138
commit
d40d2cb78d
2 changed files with 88 additions and 67 deletions
|
|
@ -3,15 +3,15 @@
|
||||||
# This example shows some of the things you in this plugin. This is how the
|
# This example shows some of the things you in this plugin. This is how the
|
||||||
# author uses it:
|
# author uses it:
|
||||||
#
|
#
|
||||||
# NOTE: make sure to add 'git-prompt' to your list of oh-my-zsh plugins (in your
|
# NOTE: make sure to add 'git' to your list of oh-my-zsh plugins (in your
|
||||||
# .zshrc) otherwise the git prompt info will not show up in your prompt.
|
# .zshrc) otherwise this git prompt info will not show up in your prompt.
|
||||||
#
|
#
|
||||||
# ---------------------- SAMPLE THEME FILE ------------------------
|
# ---------------------- SAMPLE THEME FILE ------------------------
|
||||||
#
|
#
|
||||||
# # this is a simple example PROMPT with only git info in it:
|
# # this is a simple example PROMPT with only git
|
||||||
|
# # info from this plugin in it:
|
||||||
# PROMPT='$__GIT_PROMPT_INFO# '
|
# PROMPT='$__GIT_PROMPT_INFO# '
|
||||||
#
|
#
|
||||||
#
|
|
||||||
# # Set GIT_PROMPT_SHORTCIRCUIT='off' to turn the
|
# # Set GIT_PROMPT_SHORTCIRCUIT='off' to turn the
|
||||||
# # short-circuit logic off. The short-circuit
|
# # short-circuit logic off. The short-circuit
|
||||||
# # logic will turn off the showing of dirty
|
# # logic will turn off the showing of dirty
|
||||||
|
|
@ -19,9 +19,9 @@
|
||||||
# # while the prompt is updating the dirty state
|
# # while the prompt is updating the dirty state
|
||||||
# # info. Gathering dirty-state info can take a
|
# # info. Gathering dirty-state info can take a
|
||||||
# # long time on large repositories, so if you
|
# # long time on large repositories, so if you
|
||||||
# # find that you're prompt is taking for ever to
|
# # find that your prompt is taking for ever to
|
||||||
# # show up, and you press ctrl-c, the short-
|
# # return, and you press ctrl-c, the short-
|
||||||
# # circuit logic will turn of the showing of
|
# # circuit logic will turn off the showing of
|
||||||
# # dirty state for this repository (locally) and
|
# # dirty state for this repository (locally) and
|
||||||
# # let you know, that way you won't be slowed
|
# # let you know, that way you won't be slowed
|
||||||
# # down waiting for your prompt in large git
|
# # down waiting for your prompt in large git
|
||||||
|
|
@ -30,16 +30,16 @@
|
||||||
#
|
#
|
||||||
# # GIT_PROMPT_INFO_FUNC must be set to the
|
# # GIT_PROMPT_INFO_FUNC must be set to the
|
||||||
# # function that defines your prompt info
|
# # function that defines your prompt info
|
||||||
# # in order to turn the git-prompt plugin on.
|
# # in order to turn this plugin on.
|
||||||
# # $ZSH/lib/git-prompt.zsh will cause
|
|
||||||
# # $GIT_PROMPT_INFO_FUNC to be called when the
|
# # $GIT_PROMPT_INFO_FUNC to be called when the
|
||||||
# # git prompt info needs to be updated.
|
# # git prompt info variable needs to be updated.
|
||||||
# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO'
|
# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO'
|
||||||
#
|
#
|
||||||
# GIT_PROMPT_SHOWUPSTREAM="verbose"
|
# GIT_PROMPT_SHOWUPSTREAM="verbose"
|
||||||
#
|
#
|
||||||
# # Some color settings for the format
|
# # Some color settings for my prompt format
|
||||||
# # '_C' for color:
|
# # '_C' for color:
|
||||||
|
# if [[ "$DISABLE_COLOR" != "true" ]]; then
|
||||||
# local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory
|
# local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory
|
||||||
# local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo
|
# local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo
|
||||||
# local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean
|
# local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean
|
||||||
|
|
@ -52,16 +52,19 @@
|
||||||
# local _Cs_="" # stash state
|
# local _Cs_="" # stash state
|
||||||
# # 'R'eset formating
|
# # 'R'eset formating
|
||||||
# local R="%{$terminfo[sgr0]%}"
|
# local R="%{$terminfo[sgr0]%}"
|
||||||
|
# fi
|
||||||
#
|
#
|
||||||
# # This function creates the format and content
|
# # This function creates the format and content
|
||||||
# # of the git prompt info. It shows some of the
|
# # of the git prompt info and puts the result
|
||||||
# # ways you can set up your prompt with this
|
# # in $__GIT_PROMPT_INFO. Which you can use in
|
||||||
# # plugin.
|
# # your $PROMPT (see above). This is an
|
||||||
|
# # example of some of the ways you can set up
|
||||||
|
# # your prompt with this plugin.
|
||||||
# #
|
# #
|
||||||
# # This function must set a global variable (with
|
# # NOTE: This function must set a global variable
|
||||||
# # the your git prompt format) that you include in
|
# # (with the your git prompt format) that you
|
||||||
# # your PROMPT string.
|
# # include in your PROMPT string.
|
||||||
# # NOTE: it cannot echo this info as in:
|
# # It cannot echo this info as in:
|
||||||
# # PROMPT="$(update__GIT_PROMPT_INFO)"
|
# # PROMPT="$(update__GIT_PROMPT_INFO)"
|
||||||
# # or the short-circuit logic will not work.
|
# # or the short-circuit logic will not work.
|
||||||
# #
|
# #
|
||||||
|
|
@ -69,6 +72,7 @@
|
||||||
# update__GIT_PROMPT_INFO ()
|
# update__GIT_PROMPT_INFO ()
|
||||||
# {
|
# {
|
||||||
# local g="$(_git_promt__git_dir)"
|
# local g="$(_git_promt__git_dir)"
|
||||||
|
# # short circuit if we're not in a git repo:
|
||||||
# if [ -z "$g" ]; then
|
# if [ -z "$g" ]; then
|
||||||
# __GIT_PROMPT_INFO=''
|
# __GIT_PROMPT_INFO=''
|
||||||
# return
|
# return
|
||||||
|
|
@ -154,7 +158,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
# _git_promt__git_dir accepts 0 or 1 arguments (i.e., location)
|
# _git_promt__git_dir accepts 0 or 1 arguments (i.e., location)
|
||||||
# echos location of .git repo
|
# echos the location of .git repo.
|
||||||
|
# Useful for quickly figuring out if cwd is under a git repo.
|
||||||
_git_promt__git_dir ()
|
_git_promt__git_dir ()
|
||||||
{
|
{
|
||||||
if [ -z "${1-}" ]; then
|
if [ -z "${1-}" ]; then
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,48 @@
|
||||||
# NOTE: make sure to add 'git-prompt' to your list of oh-my-zsh plugins (in your
|
# NOTE: make sure to add 'git' to your list of oh-my-zsh plugins (in your
|
||||||
# ~/.zshrc), otherwise the git prompt info will not be shown.
|
# ~/.zshrc), otherwise the git prompt info will not be shown.
|
||||||
#
|
|
||||||
#-------------------- PROMPT definition: ----------------------
|
|
||||||
# Set the prompt.
|
|
||||||
|
|
||||||
# Reset formating
|
#-------------------- Colors ----------------------
|
||||||
local R="%{$terminfo[sgr0]%}"
|
# Colors ('_C' for color):
|
||||||
|
if [[ "$DISABLE_COLOR" != "true" ]]; then
|
||||||
|
# git prompt info colors:
|
||||||
|
local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory
|
||||||
|
local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo
|
||||||
|
local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean
|
||||||
|
local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty
|
||||||
|
local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info
|
||||||
|
local _Ci_="%{$bold_color$fg[red]%}" # index info
|
||||||
|
local _Cu_clean_="" # untracked files state when clean
|
||||||
|
local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty
|
||||||
|
local _Cp_="%{${fg[cyan]}%}" # upstream info
|
||||||
|
local _Cs_="" # stash state
|
||||||
|
|
||||||
# special colors for privileged users (root)
|
# Reset formating:
|
||||||
local user_="%(!.%{$fg_bold[yellow]$bg[red]%}.%{$fg_bold[cyan]%})%n$R"
|
local R="%{$terminfo[sgr0]%}"
|
||||||
local host_="%(!.%{$fg[red]%}.%{$fg_bold[blue]%})%m$R"
|
|
||||||
local path_="%(!.%{$fg_bold[white]%}.%{$fg_bold[white]%})%~$R"
|
|
||||||
local jobs_="%(1j.%{$fg[blue]%}%j$R.)"
|
|
||||||
|
|
||||||
PROMPT='$user_$host_$path_ $__GIT_PROMPT_INFO$jobs_# '
|
# PROMPT colors:
|
||||||
|
local _Cuser_root_="%{$fg_bold[yellow]$bg[red]%}"
|
||||||
|
local _Chost_root_="%{$fg[red]%}"
|
||||||
|
local _Cpath_root_="%{$fg_bold[white]%}"
|
||||||
|
local _Cuser_="%{$fg_bold[cyan]%}"
|
||||||
|
local _Chost_="%{$fg_bold[blue]%}"
|
||||||
|
local _Cpath_="%{$fg_bold[white]%}"
|
||||||
|
local _Cjobs_="%{$fg[blue]%}"
|
||||||
|
|
||||||
local date_format_="%D{%a %b %d}, %*"
|
# RPROMPT colors:
|
||||||
local date_="%{$fg[green]%}[$date_format_]"
|
local _Cdate_="%{$fg[green]%}"
|
||||||
local return_code_="%(?..%{$fg[red]%}%? ↵ )"
|
local _Creturn_code_="%{$fg[red]%}"
|
||||||
|
local _Cvi_mode_="%{$fg_bold[cyan]%}"
|
||||||
|
fi
|
||||||
|
|
||||||
RPROMPT='$return_code_$R$date_$R'
|
|
||||||
|
|
||||||
# use the vi-mode oh-my-zsh plugin to get this:
|
|
||||||
MODE_INDICATOR="%{$fg_bold[cyan]%}-- CMD MODE -- $R"
|
|
||||||
|
|
||||||
#
|
|
||||||
#-----------------------------------------------------
|
#-----------------------------------------------------
|
||||||
# git prompt info:
|
# git prompt info:
|
||||||
|
|
||||||
# The git-prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called
|
# The git prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called
|
||||||
# when the git prompt info needs to be updated.
|
# when $__GIT_PROMPT_INFO needs to be updated.
|
||||||
GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO"
|
GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO"
|
||||||
|
|
||||||
GIT_PROMPT_SHOWUPSTREAM="verbose"
|
GIT_PROMPT_SHOWUPSTREAM="verbose"
|
||||||
GIT_PROMPT_SHORTCIRCUIT='on'
|
GIT_PROMPT_SHORTCIRCUIT='on'
|
||||||
|
|
||||||
# git_prompt_info colors ('_C' for color):
|
|
||||||
local _Cerror_="%{$fg[yellow]%}" # bad (empty) .git/ directory
|
|
||||||
local _Cb_new_repo_="%{$fg_bold[default]%}" # branch color of new repo
|
|
||||||
local _Cb_clean_="%{$fg_no_bold[green]%}" # branch color when clean
|
|
||||||
local _Cb_dirty_="%{$fg_no_bold[red]%}" # branch color when dirty
|
|
||||||
local _Cr_="%{$bold_color$fg[yellow]%}" # rebase info
|
|
||||||
local _Ci_="%{$bold_color$fg[red]%}" # index info
|
|
||||||
local _Cu_clean_="" # untracked files state when clean
|
|
||||||
local _Cu_dirty_="%{$fg_bold[red]%}" # untracked files state when dirty
|
|
||||||
local _Cp_="%{${fg[cyan]}%}" # upstream info
|
|
||||||
local _Cs_="" # stash state
|
|
||||||
|
|
||||||
local __GIT_PROMPT_INFO=''
|
local __GIT_PROMPT_INFO=''
|
||||||
# will set __GIT_PROMPT_INFO
|
# will set __GIT_PROMPT_INFO
|
||||||
update__GIT_PROMPT_INFO ()
|
update__GIT_PROMPT_INFO ()
|
||||||
|
|
@ -126,3 +122,23 @@ update__GIT_PROMPT_INFO ()
|
||||||
|
|
||||||
__GIT_PROMPT_INFO="$R$_prompt$R"
|
__GIT_PROMPT_INFO="$R$_prompt$R"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------- PROMPT definition: ----------------------
|
||||||
|
#
|
||||||
|
local user_="%(!.$_Cuser_root_.$_Cuser_)%n$R"
|
||||||
|
local host_="%(!.$_Chost_root_.$_Chost_)%m$R"
|
||||||
|
local path_="%(!.$_Cpath_root_.$_Cpath_)%~$R"
|
||||||
|
local jobs_="%(1j.$_Cjobs_%j$R.)"
|
||||||
|
|
||||||
|
PROMPT='$user_$host_$path_ $__GIT_PROMPT_INFO$jobs_# '
|
||||||
|
|
||||||
|
local date_format_='%D{%a %b %d}, %*'
|
||||||
|
local date_="${_Cdate_}[$date_format_]$R"
|
||||||
|
local return_code_="%(?..$_Creturn_code_%? ↵ )$R"
|
||||||
|
|
||||||
|
RPROMPT='$return_code_$date_'
|
||||||
|
|
||||||
|
# use the vi-mode oh-my-zsh plugin to get this:
|
||||||
|
MODE_INDICATOR="${_Cvi_mode_}-- CMD MODE -- $R"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue