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