]> git.r.bdr.sh - rbdr/dotfiles/blame - zsh/modules/prompt.zsh
Deal with double width chars
[rbdr/dotfiles] / zsh / modules / prompt.zsh
CommitLineData
fa250235
BB
1autoload -Uz promptinit && promptinit
2
3if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then
4 prompt 'off'
5fi
6
7#
8# Precmd
9#
10
11function prompt_precmd {
a40a5ec5
BB
12 git-info
13}
14
fa250235
BB
15#
16# Functions
17#
18
a40a5ec5
BB
19function virtualenv_info {
20 if [[ -z "$VIRTUAL_ENV" ]]; then
21 venv="default"
22 else
23 venv="${VIRTUAL_ENV##*/}"
24 fi
ec48932f 25 echo "🐍 ${venv}"
01e20652
BB
26}
27
28function rvm_info {
29 if [[ -z "$RUBY_VERSION" ]]; then
30 rvminfo="default"
31 else
32 rvminfo=`rvm-prompt`
33 fi
ec48932f 34 echo "💎 ${rvminfo}"
01e20652
BB
35}
36
37function nvm_info {
38 if [[ -z "$NVM_BIN" ]]; then
39 nvminfo="default"
40 else
41 nvminfo=`nvm current`
42 fi
ec48932f 43 echo "💛 ${nvminfo}"
a40a5ec5
BB
44}
45
46function box_name {
47 [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
48}
49
fa250235
BB
50#
51# ZLE widgets
52#
53
a40a5ec5 54function zle-line-init zle-keymap-select {
ec48932f
BB
55
56 # Couldn't figure out how to get tmux and iTerm to agree on how to render
57 # these characters... so there you go.
58
59 local normal_symbol="🅽"
60 local insert_symbol="🅸"
61 local error_symbol="🆇"
62
63 [ ! -z "$TMUX" ] && normal_symbol="%{$normal_symbol%2G%}"
64 [ ! -z "$TMUX" ] && insert_symbol="%{$insert_symbol%2G%}"
65 [ ! -z "$TMUX" ] && error_symbol="%{$error_symbol%2G%}"
66
67 # Show vi status / return status on the right side
68
69 local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}"
fa250235 70 if [ $KEYMAP = 'vicmd' ]; then
ec48932f 71 local edit_status="%{%F{cyan}%}$normal_symbol"
fa250235 72 else
ec48932f 73 local edit_status="%{%F{green}%}$insert_symbol"
fa250235
BB
74 fi
75
ec48932f 76 RPROMPT="${edit_status}${return_status}%{$reset_color%}"
a40a5ec5
BB
77 zle reset-prompt
78}
79zle -N zle-line-init
80zle -N zle-keymap-select
81
fa250235
BB
82#
83# Setup Prompt
84#
85
86function prompt_setup {
a40a5ec5
BB
87 setopt LOCAL_OPTIONS
88 unsetopt XTRACE KSH_ARRAYS
89 prompt_opts=(cr percent subst)
90
91 # Load required functions.
92 autoload -Uz add-zsh-hook
93
94 # Add hook for calling git-info before each command.
fa250235 95 add-zsh-hook precmd prompt_precmd
a40a5ec5
BB
96
97 # Set git-info parameters.
fa250235
BB
98 zstyle ':git:info' verbose 'no'
99 zstyle ':git:info:branch' format '@%F{cyan}%b%f'
100 zstyle ':git:info:clean' format ''
101 zstyle ':git:info:added' format '%{%F{green}%}!'
102 zstyle ':git:info:modified' format '%{%F{green}%}?'
103 zstyle ':git:info:untracked' format '%{%F{magenta}%}?'
104 zstyle ':git:info:keys' format \
a40a5ec5
BB
105 'prompt' '%b%a%m%u'
106
107 # Define prompts.
108 PROMPT='
01e20652 109%{%F{black}%}$(nvm_info) $(rvm_info) $(virtualenv_info)
e8cfa78c 110%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%}
a40a5ec5
BB
111%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ '
112}
113
fa250235
BB
114prompt_setup "$@"
115setopt PROMPT_SUBST
ec48932f
BB
116setopt PROMPT_PERCENT
117setopt TRANSIENT_RPROMPT