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