]> git.r.bdr.sh - rbdr/dotfiles/blame - zsh/modules/prompt.zsh
Update aerc
[rbdr/dotfiles] / zsh / modules / prompt.zsh
CommitLineData
fa250235
BB
1autoload -Uz promptinit && promptinit
2
7cb68b21
RBR
3function 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
11if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then
12 prompt 'off'
13fi
14
fa250235
BB
15#
16# Functions
17#
18
fab93d61
RBR
19function env_info_provider() { echo "%{%F{green}%}n/a"; }
20function env_info {
21 echo "[%{%F{cyan}%}ENV%{%F{black}%} $(env_info_provider)%{%F{black}%}]"
22}
23
24function python_info {
7cb68b21 25 pythoninfo=`cat "$(tool_versions)" | rg python | cut -d ' ' -f 2`
d5c4a1fd 26 pythoninfo=${ASDF_PYTHON_VERSION:-$pythoninfo}
3cfb2402
RBR
27 venv="${VIRTUAL_ENV##*/}"
28 echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo:-no}@${venv:-default}"
01e20652
BB
29}
30
6f7715ef
RBR
31function rust_info {
32 rustinfo=`cat "$(tool_versions)" | rg rust | cut -d ' ' -f 2`
33 rustinfo=${ASDF_RUST_VERSION:-$rustinfo}
34 echo "%{%F{red}%}rs%{%F{black}%} ${rustinfo:-no}"
01e20652
BB
35}
36
fab93d61 37function node_info {
7cb68b21 38 nodeinfo=`cat "$(tool_versions)" | rg nodejs | cut -d ' ' -f 2`
d5c4a1fd 39 nodeinfo=${ASDF_NODEJS_VERSION:-$nodeinfo}
3cfb2402 40 echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo:-no}"
a40a5ec5
BB
41}
42
6f7715ef
RBR
43function git_info {
44 branch=$(git branch --show-current 2> /dev/null)
45
46 if [ ! -z $branch ]; then
47 echo -n "@%F{cyan}$branch%f"
48
49 status_output=$(git status --short)
50
51 if echo "$status_output" | grep -q '^??'; then
52 echo -n "%{%F{magenta}%}?%f"
53 fi
54
55 if echo "$status_output" | grep -q '^ M'; then
56 echo -n "%{%F{magenta}%}!%f"
57 fi
58
59 if echo "$status_output" | grep -q '^ D'; then
60 echo -n "%{%F{magenta}%}×%f"
61 fi
62
63 if echo "$status_output" | grep -q '^A '; then
64 echo -n "%{%F{green}%}+%f"
65 fi
66 fi
67}
68
a40a5ec5
BB
69function box_name {
70 [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
71}
72
fa250235
BB
73#
74# ZLE widgets
75#
76
a40a5ec5 77function zle-line-init zle-keymap-select {
ec48932f
BB
78
79 # Couldn't figure out how to get tmux and iTerm to agree on how to render
80 # these characters... so there you go.
81
64c29a52
RBR
82 local normal_symbol="N"
83 local insert_symbol="I"
84 local error_symbol="X"
ec48932f
BB
85
86 # Show vi status / return status on the right side
87
88 local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}"
fa250235 89 if [ $KEYMAP = 'vicmd' ]; then
ec48932f 90 local edit_status="%{%F{cyan}%}$normal_symbol"
fa250235 91 else
ec48932f 92 local edit_status="%{%F{green}%}$insert_symbol"
fa250235
BB
93 fi
94
ec48932f 95 RPROMPT="${edit_status}${return_status}%{$reset_color%}"
a40a5ec5
BB
96 zle reset-prompt
97}
98zle -N zle-line-init
99zle -N zle-keymap-select
100
fa250235
BB
101#
102# Setup Prompt
103#
104
105function prompt_setup {
a40a5ec5
BB
106 setopt LOCAL_OPTIONS
107 unsetopt XTRACE KSH_ARRAYS
108 prompt_opts=(cr percent subst)
109
110 # Load required functions.
111 autoload -Uz add-zsh-hook
112
a40a5ec5
BB
113 # Define prompts.
114 PROMPT='
6f7715ef
RBR
115%{%F{black}%}$(env_info) $(node_info) $(rust_info) $(python_info)
116%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}$(git_info)%{%f%}
117%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )%% '
a40a5ec5
BB
118}
119
fa250235
BB
120prompt_setup "$@"
121setopt PROMPT_SUBST
ec48932f
BB
122setopt PROMPT_PERCENT
123setopt TRANSIENT_RPROMPT