[Fix #88] Allow arbitrary git-info formats
The terms 'prompt' and 'rprompt' are not always appropriate. A multi-line theme may choose 'line-one' and 'line-two' instead. @ColinHebert contributed to this commit.
This commit is contained in:
parent
342f6e94a3
commit
aa0c1faa19
|
@ -46,21 +46,20 @@
|
||||||
# # %S - Indicator to notify of stashed files.
|
# # %S - Indicator to notify of stashed files.
|
||||||
# zstyle ':omz:module:git' stashed 'stashed:%S'
|
# zstyle ':omz:module:git' stashed 'stashed:%S'
|
||||||
#
|
#
|
||||||
# # %U - Indicator tnotify of unmerged files.
|
# # %U - Indicator to notify of unmerged files.
|
||||||
# zstyle ':omz:module:git' unmerged 'unmerged:%U'
|
# zstyle ':omz:module:git' unmerged 'unmerged:%U'
|
||||||
#
|
#
|
||||||
# # %u - Indicator to notify of untracked files.
|
# # %u - Indicator to notify of untracked files.
|
||||||
# zstyle ':omz:module:git' untracked 'untracked:%u'
|
# zstyle ':omz:module:git' untracked 'untracked:%u'
|
||||||
#
|
#
|
||||||
# # Left prompt.
|
|
||||||
# zstyle ':omz:module:git' prompt ' git:(%b %D)'
|
|
||||||
#
|
|
||||||
# # Right prompt.
|
|
||||||
# zstyle ':omz:module:git' rprompt ''
|
|
||||||
#
|
|
||||||
# # Ignore submodule when it is 'dirty', 'untracked', 'all', or 'none'.
|
# # Ignore submodule when it is 'dirty', 'untracked', 'all', or 'none'.
|
||||||
# zstyle ':omz:module:git:ignore' submodule ''
|
# zstyle ':omz:module:git:ignore' submodule ''
|
||||||
#
|
#
|
||||||
|
# # Prompts.
|
||||||
|
# zstyle ':omz:module:git' info \
|
||||||
|
# 'prompt' ' git:(%b%D)' \
|
||||||
|
# 'rprompt' ''
|
||||||
|
#
|
||||||
|
|
||||||
# Load dependencies.
|
# Load dependencies.
|
||||||
omodload 'trap'
|
omodload 'trap'
|
||||||
|
@ -197,6 +196,8 @@ function git-info {
|
||||||
local dirty_format
|
local dirty_format
|
||||||
local dirty_formatted
|
local dirty_formatted
|
||||||
local ignore_submodule
|
local ignore_submodule
|
||||||
|
local -A info_formats
|
||||||
|
local info_format
|
||||||
local line_number=0
|
local line_number=0
|
||||||
local modified=0
|
local modified=0
|
||||||
local modified_format
|
local modified_format
|
||||||
|
@ -204,7 +205,6 @@ function git-info {
|
||||||
local position
|
local position
|
||||||
local position_format
|
local position_format
|
||||||
local position_formatted
|
local position_formatted
|
||||||
local prompt_format
|
|
||||||
local remote
|
local remote
|
||||||
local remote_cmd
|
local remote_cmd
|
||||||
local remote_format
|
local remote_format
|
||||||
|
@ -212,7 +212,6 @@ function git-info {
|
||||||
local renamed=0
|
local renamed=0
|
||||||
local renamed_format
|
local renamed_format
|
||||||
local renamed_formatted
|
local renamed_formatted
|
||||||
local rprompt_format
|
|
||||||
local stashed=0
|
local stashed=0
|
||||||
local stashed_format
|
local stashed_format
|
||||||
local stashed_formatted
|
local stashed_formatted
|
||||||
|
@ -223,12 +222,10 @@ function git-info {
|
||||||
local untracked=0
|
local untracked=0
|
||||||
local untracked_format
|
local untracked_format
|
||||||
local untracked_formatted
|
local untracked_formatted
|
||||||
local -A git_info_vars
|
|
||||||
local git_info_var
|
|
||||||
|
|
||||||
# Clean up previous git-info.
|
# Clean up previous $git_info.
|
||||||
unset git_prompt_info
|
unset git_info
|
||||||
unset git_rprompt_info
|
typeset -gA git_info
|
||||||
|
|
||||||
# Return if not inside a Git repository work tree.
|
# Return if not inside a Git repository work tree.
|
||||||
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
|
if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then
|
||||||
|
@ -384,17 +381,10 @@ function git-info {
|
||||||
zformat -f dirty_formatted "$dirty_format" "D:$dirty"
|
zformat -f dirty_formatted "$dirty_format" "D:$dirty"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Format prompts.
|
# Format info.
|
||||||
zstyle -s ':omz:module:git' prompt 'prompt_format'
|
zstyle -a ':omz:module:git' info 'info_formats'
|
||||||
zstyle -s ':omz:module:git' rprompt 'rprompt_format'
|
for info_format in ${(k)info_formats}; do
|
||||||
|
zformat -f REPLY "$info_formats[$info_format]" \
|
||||||
git_info_vars=(
|
|
||||||
git_prompt_info "$prompt_format"
|
|
||||||
git_rprompt_info "$rprompt_format"
|
|
||||||
)
|
|
||||||
|
|
||||||
for git_info_var in ${(k)git_info_vars}; do
|
|
||||||
zformat -f "$git_info_var" "$git_info_vars[$git_info_var]" \
|
|
||||||
"A:$ahead_formatted" \
|
"A:$ahead_formatted" \
|
||||||
"B:$behind_formatted" \
|
"B:$behind_formatted" \
|
||||||
"D:$dirty_formatted" \
|
"D:$dirty_formatted" \
|
||||||
|
@ -410,9 +400,12 @@ function git-info {
|
||||||
"r:$renamed_formatted" \
|
"r:$renamed_formatted" \
|
||||||
"s:$action_formatted" \
|
"s:$action_formatted" \
|
||||||
"u:$untracked_formatted"
|
"u:$untracked_formatted"
|
||||||
|
git_info[$info_format]="$REPLY"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
unset REPLY
|
||||||
unset _git_info_executing
|
unset _git_info_executing
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,14 @@ function prompt_sorin_setup {
|
||||||
zstyle ':omz:module:git' stashed ' %%B%F{cyan}✭%f%%b'
|
zstyle ':omz:module:git' stashed ' %%B%F{cyan}✭%f%%b'
|
||||||
zstyle ':omz:module:git' unmerged ' %%B%F{yellow}═%f%%b'
|
zstyle ':omz:module:git' unmerged ' %%B%F{yellow}═%f%%b'
|
||||||
zstyle ':omz:module:git' untracked ' %%B%F{white}◼%f%%b'
|
zstyle ':omz:module:git' untracked ' %%B%F{white}◼%f%%b'
|
||||||
zstyle ':omz:module:git' prompt ' %F{blue}git%f$(coalesce "%b" "%p" "%c")%s'
|
zstyle ':omz:module:git' info \
|
||||||
zstyle ':omz:module:git' rprompt '%A%B%S%a%d%m%r%U%u'
|
'prompt' ' %F{blue}git%f$(coalesce "%b" "%p" "%c")%s' \
|
||||||
|
'rprompt' '%A%B%S%a%d%m%r%U%u'
|
||||||
|
|
||||||
PROMPT='%F{cyan}%1~%f${(e)git_prompt_info} %(!.%B%F{red}#%f%b.%B%F{green}❯%f%b) '
|
PROMPT='%F{cyan}%1~%f${(e)git_info[prompt]} %(!.%B%F{red}#%f%b.%B%F{green}❯%f%b) '
|
||||||
RPROMPT='${editor_keymap_info}%(?:: %F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_rprompt_info}'
|
RPROMPT='${editor_keymap_info}%(?:: %F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_info[rprompt]}'
|
||||||
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
|
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_sorin_setup "$@"
|
prompt_sorin_setup "$@"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue