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