Parent directory

trapd00r.zsh-theme

3639 bytes
  1# trapd00r.zsh-theme
  2#
  3# This theme needs a terminal supporting 256 colors as well as unicode.
  4# In order to avoid external dependencies, it also has a zsh version of
  5# the previously used perl script https://github.com/trapd00r/utils/blob/master/zsh_path,
  6# which splits up the current path and makes it fancy.
  7#
  8# By default it spans over two lines like so:
  9#
 10# scp1@shiva:pts/9-> /home » scp1 (0)
 11# >
 12#
 13# that's  user@host:pts/-> split path (return status)
 14#
 15# If the current directory is a git repository, we span 3 lines;
 16#
 17# git❨ master ❩ DIRTY
 18# scp1@shiva:pts/4-> /home » scp1 » dev » utils (0)
 19# >
 20
 21autoload -U add-zsh-hook
 22autoload -Uz vcs_info
 23
 24local c0=$'\e[m'
 25local c1=$'\e[38;5;245m'
 26local c2=$'\e[38;5;250m'
 27local c3=$'\e[38;5;242m'
 28local c4=$'\e[38;5;197m'
 29local c5=$'\e[38;5;225m'
 30local c6=$'\e[38;5;240m'
 31local c7=$'\e[38;5;242m'
 32local c8=$'\e[38;5;244m'
 33local c9=$'\e[38;5;162m'
 34local c10=$'\e[1m'
 35local c11=$'\e[38;5;208m\e[1m'
 36local c12=$'\e[38;5;142m\e[1m'
 37local c13=$'\e[38;5;196m\e[1m'
 38
 39
 40zsh_path() {
 41  setopt localoptions nopromptsubst
 42
 43  local colors
 44  colors=$(echoti colors)
 45
 46  local -A yellow
 47  yellow=(
 48    1  '%F{228}'   2  '%F{222}'   3  '%F{192}'   4  '%F{186}'
 49    5  '%F{227}'   6  '%F{221}'   7  '%F{191}'   8  '%F{185}'
 50    9  '%F{226}'   10  '%F{220}'   11  '%F{190}'   12  '%F{184}'
 51    13  '%F{214}'   14  '%F{178}'  15  '%F{208}'   16  '%F{172}'
 52    17  '%F{202}'   18  '%F{166}'
 53  )
 54
 55  local dir i=1
 56  for dir (${(s:/:)PWD}); do
 57    if [[ $i -eq 1 ]]; then
 58      if [[ $colors -ge 256 ]]; then
 59        print -Pn "%F{065}%B /%b"
 60      else
 61        print -Pn "\e[31;1m /"
 62      fi
 63    else
 64      if [[ $colors -ge 256 ]]; then
 65        print -Pn "${yellow[$i]:-%f} » "
 66      else
 67        print -Pn "%F{yellow} > "
 68      fi
 69    fi
 70
 71    (( i++ ))
 72
 73    if [[ $colors -ge 256 ]]; then
 74      print -Pn "%F{065}$dir"
 75    else
 76      print -Pn "%F{blue}$dir"
 77    fi
 78  done
 79  print -Pn "%f"
 80}
 81
 82
 83# We don't want to use the extended colorset in the TTY / VC.
 84if [ "$TERM" = linux ]; then
 85  c1=$'\e[34;1m'
 86  c2=$'\e[35m'
 87  c3=$'\e[31m'
 88  c4=$'\e[31;1m'
 89  c5=$'\e[32m'
 90  c6=$'\e[32;1m'
 91  c7=$'\e[33m'
 92  c8=$'\e[33;1m'
 93  c9=$'\e[34m'
 94  c11=$'\e[35;1m'
 95  c12=$'\e[36m'
 96  c13=$'\e[31;1m'
 97fi
 98
 99zstyle ':vcs_info:*' actionformats \
100    '%{$c8%}(%f%s)%{$c7%}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
101
102zstyle ':vcs_info:*' formats \
103    "%{$c8%}%s%%{$c7%}❨ %{$c9%}%{$c11%}%b%{$c7%} ❩%{$reset_color%}%f "
104
105zstyle ':vcs_info:*' enable git
106
107add-zsh-hook precmd prompt_jnrowe_precmd
108
109prompt_jnrowe_precmd () {
110  vcs_info
111  if [ "${vcs_info_msg_0_}" = "" ]; then
112    dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
113    PROMPT='${dir_status} ${ret_status}%{$reset_color%}
114> '
115  # modified, to be committed
116  elif [[ $(git diff --cached --name-status 2>/dev/null ) != "" ]]; then
117    dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
118    PROMPT='${vcs_info_msg_0_}%{$30%} %{$bg_bold[red]%}%{$fg_bold[cyan]%}C%{$fg_bold[black]%}OMMIT%{$reset_color%}
119${dir_status}%{$reset_color%}
120> '
121  elif [[ $(git diff --name-status 2>/dev/null ) != "" ]]; then
122    dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
123    PROMPT='${vcs_info_msg_0_}%{$bg_bold[red]%}%{$fg_bold[blue]%}D%{$fg_bold[black]%}IRTY%{$reset_color%}
124${dir_status}%{$reset_color%}
125%{$c13%}>%{$c0%} '
126  else
127    dir_status="%{$c1%}%n%{$c4%}@%{$c2%}%m%{$c0%}:%{$c3%}%l%{$c6%}->%{$(zsh_path)%} %{$c0%}(%{$c5%}%?%{$c0%})"
128    PROMPT='${vcs_info_msg_0_}
129${dir_status}%{$reset_color%}
130> '
131  fi
132}