Parent directory

jonathan.zsh-theme

4210 bytes
  1function theme_precmd {
  2  local TERMWIDTH=$(( COLUMNS - ${ZLE_RPROMPT_INDENT:-1} ))
  3
  4  PR_FILLBAR=""
  5  PR_PWDLEN=""
  6
  7  local promptsize=${#${(%):---(%n@%m:%l)---()--}}
  8  local rubypromptsize=${#${(%)$(ruby_prompt_info)}}
  9  local pwdsize=${#${(%):-%~}}
 10  local venvpromptsize=$((${#$(virtualenv_prompt_info)}))
 11  local condapromptsize=$((${#$(conda_prompt_info)}))
 12
 13  # Truncate the path if it's too long.
 14  if (( promptsize + rubypromptsize + pwdsize + venvpromptsize + condapromptsize > TERMWIDTH )); then
 15    (( PR_PWDLEN = TERMWIDTH - promptsize ))
 16  elif [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
 17    PR_FILLBAR="\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize + venvpromptsize + condapromptsize ) ))::${PR_HBAR}:)}"
 18  else
 19    PR_FILLBAR="${PR_SHIFT_IN}\${(l:$(( TERMWIDTH - (promptsize + rubypromptsize + pwdsize + venvpromptsize + condapromptsize ) ))::${altchar[q]:--}:)}${PR_SHIFT_OUT}"
 20  fi
 21}
 22
 23function theme_preexec {
 24  setopt local_options extended_glob
 25  if [[ "$TERM" = "screen" ]]; then
 26    local CMD=${1[(wr)^(*=*|sudo|-*)]}
 27    echo -n "\ek$CMD\e\\"
 28  fi
 29}
 30
 31autoload -U add-zsh-hook
 32add-zsh-hook precmd  theme_precmd
 33add-zsh-hook preexec theme_preexec
 34
 35
 36# Set the prompt
 37
 38# Need this so the prompt will work.
 39setopt prompt_subst
 40
 41# See if we can use colors.
 42autoload zsh/terminfo
 43for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GREY; do
 44  typeset -g PR_$color="%{$terminfo[bold]$fg[${(L)color}]%}"
 45  typeset -g PR_LIGHT_$color="%{$fg[${(L)color}]%}"
 46done
 47PR_NO_COLOUR="%{$terminfo[sgr0]%}"
 48
 49# Modify Git prompt
 50ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[green]%}"
 51ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
 52ZSH_THEME_GIT_PROMPT_DIRTY=""
 53ZSH_THEME_GIT_PROMPT_CLEAN=""
 54
 55ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%} %{%G✚%}"
 56ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%} %{%G✹%}"
 57ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%} %{%G✖%}"
 58ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%} %{%G➜%}"
 59ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%} %{%G═%}"
 60ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} %{%G✭%}"
 61
 62# Use extended characters to look nicer if supported.
 63if [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
 64  PR_SET_CHARSET=""
 65  PR_HBAR="─"
 66  PR_ULCORNER="┌"
 67  PR_LLCORNER="└"
 68  PR_LRCORNER="┘"
 69  PR_URCORNER="┐"
 70else
 71  typeset -g -A altchar
 72  set -A altchar ${(s..)terminfo[acsc]}
 73  # Some stuff to help us draw nice lines
 74  PR_SET_CHARSET="%{$terminfo[enacs]%}"
 75  PR_SHIFT_IN="%{$terminfo[smacs]%}"
 76  PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
 77  PR_HBAR="${PR_SHIFT_IN}${altchar[q]:--}${PR_SHIFT_OUT}"
 78  PR_ULCORNER="${PR_SHIFT_IN}${altchar[l]:--}${PR_SHIFT_OUT}"
 79  PR_LLCORNER="${PR_SHIFT_IN}${altchar[m]:--}${PR_SHIFT_OUT}"
 80  PR_LRCORNER="${PR_SHIFT_IN}${altchar[j]:--}${PR_SHIFT_OUT}"
 81  PR_URCORNER="${PR_SHIFT_IN}${altchar[k]:--}${PR_SHIFT_OUT}"
 82fi
 83
 84# Decide if we need to set titlebar text.
 85case $TERM in
 86  xterm*)
 87    PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
 88    ;;
 89  screen)
 90    PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
 91    ;;
 92  *)
 93    PR_TITLEBAR=""
 94    ;;
 95esac
 96
 97# Decide whether to set a screen title
 98if [[ "$TERM" = "screen" ]]; then
 99  PR_STITLE=$'%{\ekzsh\e\\%}'
100else
101  PR_STITLE=""
102fi
103
104# Finally, the prompt.
105PROMPT='${PR_SET_CHARSET}${PR_STITLE}${(e)PR_TITLEBAR}${PR_CYAN}${PR_ULCORNER}${PR_HBAR}${PR_GREY}(${PR_GREEN}%${PR_PWDLEN}<...<%~%<<${PR_GREY})$(virtualenv_prompt_info)$(ruby_prompt_info)$(conda_prompt_info)${PR_CYAN}${PR_HBAR}${PR_HBAR}${(e)PR_FILLBAR}${PR_HBAR}${PR_GREY}(${PR_CYAN}%(!.%SROOT%s.%n)${PR_GREY}@${PR_GREEN}%m:%l${PR_GREY})${PR_CYAN}${PR_HBAR}${PR_URCORNER}
106${PR_CYAN}${PR_LLCORNER}${PR_BLUE}${PR_HBAR}(${PR_YELLOW}%D{%H:%M:%S}${PR_LIGHT_BLUE}%{$reset_color%}$(git_prompt_info)$(git_prompt_status)${PR_BLUE})${PR_CYAN}${PR_HBAR}${PR_HBAR}>${PR_NO_COLOUR} '
107
108# display exitcode on the right when > 0
109return_code="%(?..%{$fg[red]%}%? ↵ %{$reset_color%})"
110RPROMPT=' $return_code${PR_CYAN}${PR_HBAR}${PR_BLUE}${PR_HBAR}(${PR_YELLOW}%D{%a,%b%d}${PR_BLUE})${PR_HBAR}${PR_CYAN}${PR_LRCORNER}${PR_NO_COLOUR}'
111
112PS2='${PR_CYAN}${PR_HBAR}${PR_BLUE}${PR_HBAR}(${PR_LIGHT_GREEN}%_${PR_BLUE})${PR_HBAR}${PR_CYAN}${PR_HBAR}${PR_NO_COLOUR} '