-
Notifications
You must be signed in to change notification settings - Fork 0
/
50-prompt.sh
80 lines (77 loc) · 2.68 KB
/
50-prompt.sh
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
# Set prompt and title (for interactive shells only)
if [ "$(expr $- : '.*i')" -ne 0 ]; then
if [ -e /usr/share/git-core/git-prompt.sh ]; then
. /usr/share/git-core/git-prompt.sh
fi
# this works for sh and bash
if [ -z "$ZSH_VERSION" ]; then
# first get exit code of last command, and set colors
PS1="\$(\
EXIT=\"\$?\" ; \
BLUE=\"\[\e[38;5;39m\]\" ; \
RED=\"\[\e[31m\]\" ; \
ORANGE=\"\[\e[38;5;208m\]\" ; \
PINK=\"\[\e[38;5;201m\]\" ; \
CYAN=\"\[\e[38;5;14m\]\" ; \
GREEN=\"\[\e[38;5;10m\]\" ; \
WHITE=\"\[\e[0m\]\" ; "
# endchar
# use # for root and $ for non-root users
# use white for default color, and red if last exit code is non-zero
# username
# use red for root blue(39) for non-root users
PS1+="\
endchar=\"\\$\${WHITE}\" ; \
username=\"\${PINK}\u\${WHITE}\" ; \
if [ \"\$UID\" = \"0\" ]; then
username=\"\${RED}\u\${WHITE}\" ; \
fi ; \
if [ \"\$EXIT\" -eq 0 ]; then
endchar=\"\${GREEN}\$endchar\" ; \
else \
endchar=\"\${RED}\$endchar\"
fi ; "
# hostname in orange
PS1+="\
host=\"\${ORANGE}\H\${WHITE}\" ; "
# current directory in blue(39)
PS1+="\
dir=\"\${CYAN}\w\${WHITE}\" ; "
# set prompt, and additionally set window title for xterm
if [ "${TERM:0:5}" = "xterm" ]; then
if [ -e /usr/share/git-core/git-prompt.sh ]; then
PS1+="echo \"\[\e]2;\u@\H :: \w\a\]\${username}@\${host}\${dir}\$(__git_ps1) \n\${endchar} \" )"
else
PS1+="echo \"\[\e]2;\u@\H :: \w\a\]\${username}@\${host}\${dir} \n\${endchar} \" )"
fi
else
PS1+="echo \"\${username}@\${host} \${dir} \n\${endchar} \" )"
fi
else
# this works for zsh
# endchar
# use red if last command has non-zero exit
# use # for root and $ for non-root users
local _root_endch="%(?.#.%F{red}#%f)"
local _other_endch="%(?.$.%F{red}$%f)"
local _endchar="%(#.${_root_endch}.${_other_endch})"
# use red for root and blue(39) for non-root users
local _username="%F{%(#.red.39)}%n%f"
# hostname in orange
local _host="%F{208}%m%f"
# current directory in blue(39)
local _dir="%F{39}%~%f"
# set prompt
PS1="${_username}@${_host} ${_dir} ${_endchar} "
# additionally set window title for xterm
__stateless_title () { # for xterm, set window title
if [ "${TERM:0:5}" = "xterm" ]; then
print -Pn "\e]2;%n\@%m :: %~\a"
fi
}
__stateless_title
autoload -Uz add-zsh-hook
add-zsh-hook chpwd __stateless_title
fi
export PS1
fi