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