-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_zpromptrc
executable file
·134 lines (104 loc) · 4.1 KB
/
_zpromptrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/zsh
autoload -Uz vcs_info
zstyle ':vcs_info:*' max-exports 3
zstyle ':vcs_info:git*' check-for-changes true
zstyle ':vcs_info:git*' actionformats '(%b|%a) ' '%u%c' '%s' '%c'
zstyle ':vcs_info:git*' formats '(%b) ' '%u%c' '%s' '%c'
zstyle ':vcs_info:' enable git
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
ps1_vcs_status() {
unset ps1_vcs_space_needed ps1_git_color
unset ps1_vcs_short_info ps1_vcs_long_info
vcs_info
ps1_vcs_space_needed=1
if [[ "${vcs_info_msg_2_}" == "git" ]]; then
[[ -n "${vcs_info_msg_1_}" ]] \
&& ps1_git_color="%{$fg[red]%}" \
|| ps1_git_color="%{$fg[green]%}"
ps1_vcs_space_needed=$((ps1_vcs_space_needed + 1))
ps1_vcs_short_info="${ps1_git_color}⭠"
ps1_vcs_long_info=${ps1_git_color}${vcs_info_msg_0_}
fi
[[ $ps1_vcs_space_needed -eq 1 ]] && ps1_vcs_space_needed=0
[[ -n ${ps1_vcs_short_info} ]] && ps1_vcs_short_info+=" "
}
ps1_fill_line() {
unset ps1_fill_size
ps1_fill_size=$1
# if I don't have enough space to fit everything
if [[ ${ps1_fill_size} < 0 ]]; then
# remove the user/host name and try again
PS1=${line_color}"┌─"
ps1_fill_size=$(($COLUMNS - ${ps1_cwd_size} - ${ps1_venv_size} - 9))
# if I still don't have enough, truncate the cwd and hint for any extra
if [[ ${ps1_fill_size} < 0 ]]
then
ps1_new_cwd=...${ps1_cwd:$((12 + ${ps1_vcs_space_needed}\
${ps1_venv:+"+ 2"} \
- $COLUMNS))}
if [[ ${#ps1_new_cwd} -ge ${#ps1_cwd} ]]; then
ps1_new_cwd=${ps1_cwd}
fi
ps1_fill_size=$(($COLUMNS - ${#ps1_new_cwd} ${ps1_venv:+"- 2"} \
- $ps1_vcs_space_needed - 9))
# if after all that it's /still/ not enough, then just set it to 0
if [[ ${ps1_fill_size} < 0 ]]; then ps1_fill_size=0; fi
ps1_cwd=${ps1_venv:+"%{$fg[blue]%}V "}
ps1_cwd+="${ps1_cwd_color}${ps1_new_cwd}"
ps1_venv=""
unset ps1_new_cwd
fi
fi
while ((ps1_fill_size-- > 0)); do PS1+='─'; done
}
precmd() {
# PS1 {{{
# set the error code
ps1_errno=$?
if [ ${ps1_errno} -eq 0 ]; then
ps1_errno=""
line_color="%{$reset_color%}"
ps1_tail+="%{$fg[magenta]%}"
else
line_color="%{$fg[red]%}"
ps1_tail+="%{$fg[red]%}"
fi
ps1_tail+="%B%#%b %{$reset_color%}"
ps1_vcs_status
ps1_venv_size=0
ps1_venv=""
if [[ -n ${VIRTUAL_ENV} ]]; then
ps1_venv="`basename $VIRTUAL_ENV`"
ps1_venv_size=$((${#ps1_venv} + 7))
ps1_venv="─┤ %{$fg[blue]%}${ps1_venv}%{$line_color%} ├──"
fi
# print the LHS of the prompt
PS1=${line_color}"┌─┤ %{$fg[green]%}"${USER}
PS1+=${line_color}"@%{$fg[blue]%}"${HOST}
PS1+="%{$reset_color%}"${SSH_CLIENT:+"(ssh)"}${line_color}" ├"
# fill the line until the end
ps1_cwd=${PWD/$HOME/\~}
[[ -w $PWD ]] && ps1_cwd_color="%{$reset_color%}" \
|| ps1_cwd_color="%{$fg[red]%}"
ps1_cwd_size=$((${#ps1_cwd} + $ps1_vcs_space_needed))
ps1_fill_line $((${COLUMNS} - ${#USER} - ${#HOST} - ${ps1_cwd_size} \
${SSH_CLIENT:+" - 5"} - ${ps1_venv_size} - 14))
# print the RHS of the prompt
PS1+=${ps1_venv}
PS1+=${line_color}"┤ "${ps1_vcs_short_info}
PS1+="${ps1_cwd_color}${ps1_cwd}%{$reset_color%} ${line_color}├─┐"
PS1+=$'\n'"%{${line_color}%}└─ "
PS1+="${ps1_vcs_long_info}${ps1_tail}%{$reset_color%}"
RPS1="%{${line_color}%}%{%B%}${ps1_errno}%{%b%}"
RPS1+="%{${line_color}%} ─┘%{$reset_color%}"
unset ps1_errno ps1_fill_size line_color ps1_tail ps1_cwd_color
unset ps1_cwd ps1_cwd_size ps1_git ps1_git_color ps1_venv
# }}}
}
# secondary prompt, printed when the shell needs more information to complete a
# command.
PS2='%_> '
# selection prompt used within a select loop.
PS3='?# '
# the execution trace prompt (setopt xtrace). default: '+%N:%i>'
PS4='+%N:%i:%_> '