]>
Commit | Line | Data |
---|---|---|
1 | autoload -Uz promptinit && promptinit | |
2 | ||
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 | ||
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 { | |
20 | git-info | |
21 | } | |
22 | ||
23 | # | |
24 | # Functions | |
25 | # | |
26 | ||
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 { | |
33 | pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2` | |
34 | pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo} | |
35 | venv="${VIRTUAL_ENV##*/}" | |
36 | echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}" | |
37 | } | |
38 | ||
39 | function ruby_info { | |
40 | rubyinfo=`cat "$(tool_versions)" | rg ruby | cut -d ' ' -f 2` | |
41 | rubyinfo=${ASDF_RUBY_VERSION:-$rubyinfo} | |
42 | echo "%{%F{red}%}rb%{%F{black}%} ${rubyinfo:-no}" | |
43 | } | |
44 | ||
45 | function node_info { | |
46 | nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2` | |
47 | nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo} | |
48 | echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}" | |
49 | } | |
50 | ||
51 | function box_name { | |
52 | [ -f ~/.box-name ] && cat ~/.box-name || hostname -s | |
53 | } | |
54 | ||
55 | # | |
56 | # ZLE widgets | |
57 | # | |
58 | ||
59 | function zle-line-init zle-keymap-select { | |
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 | ||
64 | local normal_symbol="N" | |
65 | local insert_symbol="I" | |
66 | local error_symbol="X" | |
67 | ||
68 | # Show vi status / return status on the right side | |
69 | ||
70 | local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}" | |
71 | if [ $KEYMAP = 'vicmd' ]; then | |
72 | local edit_status="%{%F{cyan}%}$normal_symbol" | |
73 | else | |
74 | local edit_status="%{%F{green}%}$insert_symbol" | |
75 | fi | |
76 | ||
77 | RPROMPT="${edit_status}${return_status}%{$reset_color%}" | |
78 | zle reset-prompt | |
79 | } | |
80 | zle -N zle-line-init | |
81 | zle -N zle-keymap-select | |
82 | ||
83 | # | |
84 | # Setup Prompt | |
85 | # | |
86 | ||
87 | function prompt_setup { | |
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. | |
96 | add-zsh-hook precmd prompt_precmd | |
97 | ||
98 | # Set git-info parameters. | |
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 \ | |
106 | 'prompt' '%b%a%m%u' | |
107 | ||
108 | # Define prompts. | |
109 | PROMPT=' | |
110 | %{%F{black}%}$(env_info) $(node_info) $(ruby_info) $(python_info) | |
111 | %{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%} | |
112 | %(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ ' | |
113 | } | |
114 | ||
115 | prompt_setup "$@" | |
116 | setopt PROMPT_SUBST | |
117 | setopt PROMPT_PERCENT | |
118 | setopt TRANSIENT_RPROMPT |