]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - zsh/modules/prompt.zsh
Update karabiner config
[rbdr/dotfiles] / zsh / modules / prompt.zsh
... / ...
CommitLineData
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 {
12 git-info
13}
14
15#
16# Functions
17#
18
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 {
25 pythoninfo=`asdf current python | sed 's/ */ /g' | cut -d ' ' -f 2`
26 if [[ -z "$VIRTUAL_ENV" ]]; then
27 venv="default"
28 else
29 venv="${VIRTUAL_ENV##*/}"
30 fi
31 echo "%{%F{green}%}py%{%F{black}%} ${pythoninfo}@${venv}"
32}
33
34function ruby_info {
35 rubyinfo=`asdf current ruby | sed 's/ */ /g' | cut -d ' ' -f 2`
36 echo "%{%F{red}%}rb%{%F{black}%} ${rubyinfo}"
37}
38
39function node_info {
40 nodeinfo=`asdf current nodejs | sed 's/ */ /g' | cut -d ' ' -f 2`
41 echo "%{%F{yellow}%}js%{%F{black}%} ${nodeinfo}"
42}
43
44function box_name {
45 [ -f ~/.box-name ] && cat ~/.box-name || hostname -s
46}
47
48#
49# ZLE widgets
50#
51
52function zle-line-init zle-keymap-select {
53
54 # Couldn't figure out how to get tmux and iTerm to agree on how to render
55 # these characters... so there you go.
56
57 local normal_symbol="N"
58 local insert_symbol="I"
59 local error_symbol="X"
60
61 # Show vi status / return status on the right side
62
63 local return_status="%{%F{red}%}%(?.. $error_symbol)%{$reset_color%}"
64 if [ $KEYMAP = 'vicmd' ]; then
65 local edit_status="%{%F{cyan}%}$normal_symbol"
66 else
67 local edit_status="%{%F{green}%}$insert_symbol"
68 fi
69
70 RPROMPT="${edit_status}${return_status}%{$reset_color%}"
71 zle reset-prompt
72}
73zle -N zle-line-init
74zle -N zle-keymap-select
75
76#
77# Setup Prompt
78#
79
80function prompt_setup {
81 setopt LOCAL_OPTIONS
82 unsetopt XTRACE KSH_ARRAYS
83 prompt_opts=(cr percent subst)
84
85 # Load required functions.
86 autoload -Uz add-zsh-hook
87
88 # Add hook for calling git-info before each command.
89 add-zsh-hook precmd prompt_precmd
90
91 # Set git-info parameters.
92 zstyle ':git:info' verbose 'no'
93 zstyle ':git:info:branch' format '@%F{cyan}%b%f'
94 zstyle ':git:info:clean' format ''
95 zstyle ':git:info:added' format '%{%F{green}%}!'
96 zstyle ':git:info:modified' format '%{%F{green}%}?'
97 zstyle ':git:info:untracked' format '%{%F{magenta}%}?'
98 zstyle ':git:info:keys' format \
99 'prompt' '%b%a%m%u'
100
101 # Define prompts.
102 PROMPT='
103%{%F{black}%}$(env_info) $(node_info) $(ruby_info) $(python_info)
104%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%}
105%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ '
106}
107
108prompt_setup "$@"
109setopt PROMPT_SUBST
110setopt PROMPT_PERCENT
111setopt TRANSIENT_RPROMPT