prompt.zsh (2547B)
1 # PROMPT 2 3 ICO_DIRTY="⚡" 4 ICO_AHEAD="▲" 5 ICO_BEHIND="▼" 6 ICO_DIVERGED="⥮" 7 COLOR_ROOT="%F{red}" 8 COLOR_USER="%F{cyan}" 9 COLOR_NORMAL="%F{white}" 10 PROMPT_STYLE="tiny" 11 12 # allow functions in the prompt 13 setopt PROMPT_SUBST 14 autoload -Uz colors && colors 15 16 # autoload zsh functions 17 fpath=(~/.zsh/functions $fpath) 18 autoload -U ~/.zsh/functions/*(:t) 19 20 # enable auto-execution of functions 21 typeset -ga chpwd_functions 22 23 # prepend functions 24 chpwd_functions+=('chpwd_auto_cd') 25 mpv_functions+=('mm') 26 27 # colors for permissions 28 if [[ "$EUID" -ne "0" ]] 29 then # if user is not root 30 USER_LEVEL="${COLOR_USER}" 31 else # root! 32 USER_LEVEL="${COLOR_ROOT}" 33 fi 34 35 # git prompt 36 GIT_PROMPT() { 37 test=$(git rev-parse --is-inside-work-tree 2> /dev/null) 38 if [ ! "$test" ] 39 then 40 case "$PROMPT_STYLE" in 41 ascii) 42 echo "$reset_color%F{cyan}▒░" 43 ;; 44 arrows) 45 echo "$reset_color%F{cyan}" 46 ;; 47 esac 48 return 49 fi 50 ref=$(git name-rev --name-only HEAD | sed 's!remotes/!!' 2> /dev/null) 51 if [[ ${ref} == "tags"* ]] ; then 52 branch=$(git branch | grep -e "^*" | tr -d "*") 53 ref="${branch/ /} ${ref}" 54 fi 55 dirty="" && [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && dirty=$ICO_DIRTY 56 stat=$(git status | sed -n 2p) 57 case "$stat" in 58 *ahead*) 59 stat=$ICO_AHEAD 60 ;; 61 *behind*) 62 stat=$ICO_BEHIND 63 ;; 64 *diverged*) 65 stat=$ICO_DIVERGED 66 ;; 67 *) 68 stat="" 69 ;; 70 esac 71 case "$PROMPT_STYLE" in 72 classic) 73 echo "${COLOR_NORMAL}─["${ref}${dirty}${stat}"]" 74 ;; 75 tiny) 76 echo "%F{241} [%F{244}"${ref}${dirty}${stat}"%F{241}]" 77 ;; 78 *) 79 echo "${USER_LEVEL}─[${COLOR_NORMAL}"${ref}${dirty}${stat}"${USER_LEVEL}]" 80 ;; 81 esac 82 } 83 case "$PROMPT_STYLE" in 84 # ascii 85 ascii) 86 PROMPT='%{$bg[cyan]%} %F{black}%~ $(GIT_PROMPT)$reset_color 87 %f' 88 ;; 89 # dual line 90 dual) 91 PROMPT='${USER_LEVEL}┌[${COLOR_NORMAL}%~${USER_LEVEL}]$(GIT_PROMPT) 92 ${USER_LEVEL}└─ - %f' 93 ;; 94 # mini 95 mini) 96 PROMPT='${USER_LEVEL}[${COLOR_NORMAL}%~${USER_LEVEL}]$(GIT_PROMPT)── - %f' 97 ;; 98 # tiny 99 tiny) 100 #PROMPT='%F{3} %%${COLOR_NORMAL} ' 101 # change prompt colour if started from vim 102 if [[ -v VIMRUNTIME ]] ; then 103 PROMPT='%F{9} ──── ─${COLOR_NORMAL} ' 104 # change prompt to show hostname if over ssh 105 elif [[ -v SSH_TTY ]] ; then 106 PROMPT='%F{13} ${HOSTNAME}%F{3}_ ${COLOR_NORMAL}' 107 else 108 PROMPT='%F{11} ──── ─${COLOR_NORMAL} ' 109 fi 110 RPROMPT='%F{15}%~ $(GIT_PROMPT) ${COLOR_NORMAL}' 111 ;; 112 # classic 113 *) 114 PROMPT='%F{cyan}${USERNAME}@%F{white}[${HOSTNAME}]$(GIT_PROMPT)%F{white} : %~# ' 115 ;; 116 esac