Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (106 sloc) 2.84 KB
PROMPT=''
RPROMPT="%(?..%{$terminfo[bold]$fg[green]%}[%{$fg[red]%}%?%{$fg[green]%}]%{$terminfo[sgr0]%})"
PROMPT_SYM_COLOR=''
PROMPT_SUFFIX=''
_USER_PREFIX=''
_REMOTE_USER_PREFIX="${USER}%{$fg[green]%}@%{$fg[blue]%}${HOST} %{$fg[blue]%}"
function generate_prompt {
_SHOW_DYNAMIC_PROMPT=true
_REPO_DIRTY=''
_REPO_BRANCH=''
_REPO_BRANCH_STATUS=''
_PROMPT_PREFIX=''
if $_REMOTE; then
_USER_PREFIX=$_REMOTE_USER_PREFIX
fi
if [ "$UID" = "0" ]; then
PROMPT_SYM_COLOR="$fg[red]"
else
PROMPT_SYM_COLOR="$fg[green]"
fi
if $_ZSH_DYNAMIC_PROMPT; then
if [ -d ".hg" ]; then
[ -z "$(hg diff 2>/dev/null)" ] || _REPO_DIRTY=''
_REPO_BRANCH="$(hg branch 2>/dev/null)"
PROMPT_SUFFIX=''
elif [ -d ".git" ]; then
local st="$(git status 2>/dev/null)"
if [ -n "$st" ]; then
local -a arr
arr=(${(f)st})
local s=" "
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
s+='no-branch'
else
s+="${arr[1][(w)4]}";
fi
if [[ $arr[2] =~ 'Your branch is' ]]; then
if [[ $arr[2] =~ 'ahead' ]]; then
s+="" # Branch is ahead of master
elif [[ $arr[2] =~ 'diverged' ]]; then
s+="" # Branch is diverged from master
else
s+="" # Branch is behind master
fi
fi
# Repo is "dirty"
[[ $st =~ 'nothing to commit' ]] || s+="%{$fg[red]%}⚡%{$PROMPT_SYM_COLOR%}"
fi
PROMPT_SUFFIX="$s+"
else
_SHOW_DYNAMIC_PROMPT=false
fi
else
_SHOW_DYNAMIC_PROMPT=false
fi
if $_SHOW_DYNAMIC_PROMPT; then
echo -n; # Do nothing
elif [ "$UID" = "0" ]; then
# Generic, root user
PROMPT_SUFFIX='#'
else
# Generic, non-root user
PROMPT_SUFFIX='$'
fi
if [ $_ZSH_TODO_PROMPT ]; then
if [ -n "$($__ZSH_TODO_EXEC)" ]; then
_PROMPT_PREFIX="%{$fg[red]%}✔ "
fi
fi
PROMPT="%{$terminfo[bold]%}${_PROMPT_PREFIX}%{${PROMPT_SYM_COLOR}%}[%{$fg[blue]%}${_USER_PREFIX}%30<..<%~%{$PROMPT_SYM_COLOR%}]${PROMPT_SUFFIX}%{$terminfo[sgr0]%} "
}
function chpwd {
case $TERM in
*xterm*|*rxvt*|ansi) print -Pn "\e]2;%/ | %y\a" # better for remote shells: "\e]2;%n@%m: %~\a"
;;
screen) print -Pn "\e_ %/ | %y\e\\" # better for remote shells: "\e_ %n@%m: %~\e\\"
;;
esac
}
# Before prompt
function precmd {
generate_prompt
case $TERM in
*xterm*|*rxvt*|ansi) print -Pn "\e]2;%/ | %y\a" # better for remote shells: "\e]2;%n@%m: %~\a"
;;
screen) print -Pn "\e_ %/ | %y\e\\" # better for remote shells: "\e_ %n@%m: %~\e\\"
;;
esac
}
# After enter but before command
function preexec {
#if [ "${1:0:1}" = "," ]; then
# echo $1
# DIR="${1:2}"
# #mkdir $DIR
# #cd $DIR
#fi
local CMD="${1//\%/%%}"
case $TERM in
*xterm*|*rxvt*|ansi) print -nPR $'\e]0;'"${CMD} | %y"$'\a' # better for remote shells: "\e]2;%n@%m: $1\a"
;;
screen) print -nPR $'\e_ '"${CMD} | %y"$'\e\\' # better for remote shells: "\e_ %n@%m: $1\e\\"
;;
esac
}
chpwd # So it sets the prompt initially
Jump to Line
Something went wrong with that request. Please try again.