]>
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 | ||
a40a5ec5 BB |
19 | function virtualenv_info { |
20 | if [[ -z "$VIRTUAL_ENV" ]]; then | |
21 | venv="default" | |
22 | else | |
23 | venv="${VIRTUAL_ENV##*/}" | |
24 | fi | |
01e20652 BB |
25 | echo "🐍${venv}" |
26 | } | |
27 | ||
28 | function rvm_info { | |
29 | if [[ -z "$RUBY_VERSION" ]]; then | |
30 | rvminfo="default" | |
31 | else | |
32 | rvminfo=`rvm-prompt` | |
33 | fi | |
34 | echo "💎${rvminfo}" | |
35 | } | |
36 | ||
37 | function nvm_info { | |
38 | if [[ -z "$NVM_BIN" ]]; then | |
39 | nvminfo="default" | |
40 | else | |
41 | nvminfo=`nvm current` | |
42 | fi | |
43 | echo "💛${nvminfo}" | |
a40a5ec5 BB |
44 | } |
45 | ||
46 | function box_name { | |
47 | [ -f ~/.box-name ] && cat ~/.box-name || hostname -s | |
48 | } | |
49 | ||
fa250235 BB |
50 | # |
51 | # ZLE widgets | |
52 | # | |
53 | ||
a40a5ec5 | 54 | function zle-line-init zle-keymap-select { |
fa250235 BB |
55 | local return_status="%{%F{red}%}%(?..🆇)%{$reset_color%}" |
56 | if [ $KEYMAP = 'vicmd' ]; then | |
57 | local edit_status="%{%F{cyan}%}🅽" | |
58 | else | |
59 | local edit_status="%{%F{green}%}🅸" | |
60 | fi | |
61 | ||
62 | RPS1="${edit_status} ${return_status}%{$reset_color%}" | |
a40a5ec5 BB |
63 | RPS2=$RPS1 |
64 | zle reset-prompt | |
65 | } | |
66 | zle -N zle-line-init | |
67 | zle -N zle-keymap-select | |
68 | ||
fa250235 BB |
69 | # |
70 | # Setup Prompt | |
71 | # | |
72 | ||
73 | function prompt_setup { | |
a40a5ec5 BB |
74 | setopt LOCAL_OPTIONS |
75 | unsetopt XTRACE KSH_ARRAYS | |
76 | prompt_opts=(cr percent subst) | |
77 | ||
78 | # Load required functions. | |
79 | autoload -Uz add-zsh-hook | |
80 | ||
81 | # Add hook for calling git-info before each command. | |
fa250235 | 82 | add-zsh-hook precmd prompt_precmd |
a40a5ec5 BB |
83 | |
84 | # Set git-info parameters. | |
fa250235 BB |
85 | zstyle ':git:info' verbose 'no' |
86 | zstyle ':git:info:branch' format '@%F{cyan}%b%f' | |
87 | zstyle ':git:info:clean' format '' | |
88 | zstyle ':git:info:added' format '%{%F{green}%}!' | |
89 | zstyle ':git:info:modified' format '%{%F{green}%}?' | |
90 | zstyle ':git:info:untracked' format '%{%F{magenta}%}?' | |
91 | zstyle ':git:info:keys' format \ | |
a40a5ec5 BB |
92 | 'prompt' '%b%a%m%u' |
93 | ||
94 | # Define prompts. | |
95 | PROMPT=' | |
01e20652 | 96 | %{%F{black}%}$(nvm_info) $(rvm_info) $(virtualenv_info) |
e8cfa78c | 97 | %{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%} |
a40a5ec5 BB |
98 | %(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ ' |
99 | } | |
100 | ||
fa250235 BB |
101 | prompt_setup "$@" |
102 | setopt PROMPT_SUBST |