]>
Commit | Line | Data |
---|---|---|
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 { | |
12 | git-info | |
13 | } | |
14 | ||
15 | # | |
16 | # Functions | |
17 | # | |
18 | ||
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` | |
26 | if [[ -z "$VIRTUAL_ENV" ]]; then | |
27 | venv="default" | |
28 | else | |
29 | venv="${VIRTUAL_ENV##*/}" | |
30 | fi | |
31 | echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo}@${venv}" | |
32 | } | |
33 | ||
34 | function ruby_info { | |
35 | rubyinfo=`asdf current ruby | sed 's/ */ /g' | cut -d ' ' -f 2` | |
36 | echo "%{%F{red}%}rb%{%F{black}%} ${rubyinfo}" | |
37 | } | |
38 | ||
39 | function node_info { | |
40 | nodeinfo=`asdf current nodejs | sed 's/ */ /g' | cut -d ' ' -f 2` | |
41 | echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo}" | |
42 | } | |
43 | ||
44 | function box_name { | |
45 | [ -f ~/.box-name ] && cat ~/.box-name || hostname -s | |
46 | } | |
47 | ||
48 | # | |
49 | # ZLE widgets | |
50 | # | |
51 | ||
52 | function zle-line-init zle-keymap-select { | |
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 | ||
57 | local normal_symbol="N" | |
58 | local insert_symbol="I" | |
59 | local error_symbol="X" | |
60 | ||
61 | # Show vi status / return status on the right side | |
62 | ||
63 | local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}" | |
64 | if [ $KEYMAP = 'vicmd' ]; then | |
65 | local edit_status="%{%F{cyan}%}$normal_symbol" | |
66 | else | |
67 | local edit_status="%{%F{green}%}$insert_symbol" | |
68 | fi | |
69 | ||
70 | RPROMPT="${edit_status}${return_status}%{$reset_color%}" | |
71 | zle reset-prompt | |
72 | } | |
73 | zle -N zle-line-init | |
74 | zle -N zle-keymap-select | |
75 | ||
76 | # | |
77 | # Setup Prompt | |
78 | # | |
79 | ||
80 | function prompt_setup { | |
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. | |
89 | add-zsh-hook precmd prompt_precmd | |
90 | ||
91 | # Set git-info parameters. | |
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 \ | |
99 | 'prompt' '%b%a%m%u' | |
100 | ||
101 | # Define prompts. | |
102 | PROMPT=' | |
103 | %{%F{black}%}$(env_info) $(node_info) $(ruby_info) $(python_info) | |
104 | %{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%} | |
105 | %(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ ' | |
106 | } | |
107 | ||
108 | prompt_setup "$@" | |
109 | setopt PROMPT_SUBST | |
110 | setopt PROMPT_PERCENT | |
111 | setopt TRANSIENT_RPROMPT |