mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-29 04:53:17 +02:00
This patch adds missing % character escaping for custom git prompts used in a few themes. It also includes escaping for git-prompt.sh. In combination with CVE-2021-45444, this could allow code execution when displaying branch information in cloned malicious git repositories. However, zsh 5.8.1 and newer are largely the default zsh versions, and on those supported distributions with older zsh versions, the CVE has been found to be also patched. For this reason, this doesn't qualify as a security patch, but a bug fix for proper printing of git branches.
73 lines
2.3 KiB
Bash
73 lines
2.3 KiB
Bash
function my_git_prompt() {
|
||
tester=$(git rev-parse --git-dir 2> /dev/null) || return
|
||
|
||
INDEX=$(git status --porcelain 2> /dev/null)
|
||
STATUS=""
|
||
|
||
# is branch ahead?
|
||
if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
|
||
fi
|
||
|
||
# is branch behind?
|
||
if $(echo "$(git log HEAD..origin/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
|
||
fi
|
||
|
||
# is anything staged?
|
||
if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
|
||
fi
|
||
|
||
# is anything unstaged?
|
||
if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
|
||
fi
|
||
|
||
# is anything untracked?
|
||
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
||
fi
|
||
|
||
# is anything unmerged?
|
||
if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then
|
||
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
|
||
fi
|
||
|
||
if [[ -n $STATUS ]]; then
|
||
STATUS=" $STATUS"
|
||
fi
|
||
|
||
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(my_current_branch)$STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
||
}
|
||
|
||
function my_current_branch() {
|
||
local branch
|
||
branch=$(git_current_branch || echo "(no branch)")
|
||
echo "${branch//\%/%%}"
|
||
}
|
||
|
||
function ssh_connection() {
|
||
if [[ -n $SSH_CONNECTION ]]; then
|
||
echo "%{$fg_bold[red]%}(ssh) "
|
||
fi
|
||
}
|
||
|
||
function _toolbox_prompt_info() {
|
||
if typeset -f toolbox_prompt_info > /dev/null; then
|
||
toolbox_prompt_info
|
||
fi
|
||
}
|
||
|
||
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
|
||
PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
|
||
|
||
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
|
||
ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white]‹ %{$fg_bold[yellow]%}"
|
||
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑"
|
||
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_bold[green]%}↓"
|
||
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●"
|
||
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[red]%}●"
|
||
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[white]%}●"
|
||
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}✕"
|
||
ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg_bold[white]›%{$reset_color%}"
|