Fork of the mortalscumbag theme, including a ranger level indicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then | |
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" | |
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() { | |
echo $(current_branch || echo "(no branch)") | |
} | |
function ssh_connection() { | |
if [[ -n $SSH_CONNECTION ]]; then | |
echo "%{$fg_bold[red]%}(ssh) " | |
fi | |
} | |
function my_ranger_prompt() { | |
if [[ $RANGER_LEVEL -eq 1 ]]; then | |
echo " %{$fg_bold[white]%}[ranger]%{$reset_color%}" | |
elif [[ $RANGER_LEVEL -gt 1 ]]; then | |
echo " %{$fg_bold[red]%}[ranger]%{$reset_color%}" | |
fi | |
} | |
function standard_prompt() { | |
echo "$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%} : %3~" | |
} | |
function compute_spaces() { | |
local zero='%([BSUbfksu]|([FB]|){*})' | |
local git_prompt="$(my_git_prompt)" | |
local git_prompt_size="${#${(S%%)git_prompt//$~zero/}}" | |
local std_prompt="$(standard_prompt)" | |
local std_prompt_size="${#${(S%%)std_prompt//$~zero/}}" | |
local NB_SPACE | |
(( NB_SPACE = ${COLUMNS} - 1 - ${git_prompt_size} - ${std_prompt_size} )) | |
if [ ${git_prompt_size} -ne 1 ]; then | |
(( NB_SPACE = ${NB_SPACE} + 16 )) | |
fi | |
local spaces="" | |
for i in {1..$NB_SPACE}; do | |
spaces="${spaces} " | |
done | |
echo "${spaces}" | |
# echo "[${std_prompt_size} - ${git_prompt_size}]" | |
} | |
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" | |
PROMPT=$'\n$(standard_prompt)$(compute_spaces)$(my_git_prompt)\n%# ' | |
RPROMPT=$'[${ret_status}]$(my_ranger_prompt)' | |
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" | |
ZSH_THEME_GIT_PROMPT_PREFIX=" $fg_bold[white]‹ %{$fg_bold[yellow]%}" | |
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[magenta]%}↑" | |
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%}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment