keylanzsh

My edit of the Dieter Zsh theme
git clone git://git.ckyln.com/keylanzsh.git
Log | Files | Refs

keylan.zsh-theme (2273B)


      1 # Cem Keylan's edit of the dieter theme
      2 
      3 # the idea of this theme is to contain a lot of info in a small string, by
      4 # compressing some parts and colorcoding, which bring useful visual cues,
      5 # while limiting the amount of colors and such to keep it easy on the eyes.
      6 # When a command exited >0, the timestamp will be in red and the exit code
      7 # will be on the right edge.
      8 # The exit code visual cues will only display once.
      9 # (i.e. they will be reset, even if you hit enter a few times on empty command prompts)
     10 
     11 typeset -A host_repr
     12 
     13 # translate hostnames into shortened, colorcoded strings
     14 host_repr=('dieter-ws-a7n8x-arch' "%{$fg_bold[green]%}ws" 'dieter-p4sci-arch' "%{$fg_bold[blue]%}p4")
     15 
     16 # local time, color coded by last return code
     17 time_enabled="%(?.%{$fg[green]%}.%{$fg[red]%})%*%{$reset_color%}"
     18 time_disabled="%{$fg[green]%}%*%{$reset_color%}"
     19 time=$time_disabled
     20 
     21 # user part, color coded by privileges
     22 local user="%(!.%{$fg_bold[yellow]%}.%{$fg_bold[yellow]%})%n%{$reset_color%}"
     23 
     24 # Hostname part.  compressed and colorcoded per host_repr array
     25 # if not found, regular hostname in default color
     26 local host="%(?.%{$fg_bold[green]%}.%{$fg_bold[green]%})@%(?.%{$fg_bold[cyan]%}.%{$fg_bold[cyan]%})${host_repr[$HOST]:-$HOST}%{$reset_color%}"
     27 
     28 # Compacted $PWD
     29 local pwd="%{$fg_bold[red]%}%c%{$reset_color%}"
     30 
     31 PROMPT='${user}${host} ${pwd} $(git_prompt_info)%(?.%{$fg_bold[cyan]%}.%{$fg_bold[cyan]%})->%{$reset_color%} '
     32 
     33 # i would prefer 1 icon that shows the "most drastic" deviation from HEAD,
     34 # but lets see how this works out
     35 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%}"
     36 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
     37 ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[green]%} %{$fg_bold[yellow]%}?%{$fg_bold[green]%}%{$reset_color%}"
     38 ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}"
     39 
     40 # elaborate exitcode on the right when >0
     41 return_code_enabled="%(?..%{$fg_bold[red]%}%? ↵%{$reset_color%})"
     42 return_code_disabled=
     43 return_code=$return_code_enabled
     44 
     45 RPS1='${return_code}'
     46 
     47 function accept-line-or-clear-warning () {
     48 	if [[ -z $BUFFER ]]; then
     49 		time=$time_disabled
     50 		return_code=$return_code_disabled
     51 	else
     52 		time=$time_enabled
     53 		return_code=$return_code_enabled
     54 	fi
     55 	zle accept-line
     56 }
     57 zle -N accept-line-or-clear-warning
     58 bindkey '^M' accept-line-or-clear-warning