/
.prompt
51 lines (41 loc) · 1.42 KB
/
.prompt
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
#!/bin/bash
bash_prompt() {
case $TERM in
@(xterm|rxvt)*)
local TITLEBAR='\[\e]0;\u:${NEW_PWD}\007\]' ;;
esac
local NONE='\[\e[0m\]' # unsets color to term's fg color
# regular colors
local K='\[\e[0;30m\]' R='\[\e[0;31m\]' G='\[\e[0;32m\]' Y='\[\e[0;33m\]' \
B='\[\e[0;34m\]' M='\[\e[0;35m\]' C='\[\e[0;36m\]' W='\[\e[0;37m\]'
# emphasized (bolded) colors
local EMK='\[\e[1;30m\]' EMR='\[\e[1;31m\]' EMG='\[\e[1;32m\]' EMY='\[\e[1;33m\]' \
EMB='\[\e[1;34m\]' EMM='\[\e[1;35m\]' EMC='\[\e[1;36m\]' EMW='\[\e[1;37m\]'
# username/host color for root/other
(( UID != 0 )) && local UC=$W || local UC=$R
local RET_VALUE='$((( RET )) && printf ":\[\e[1;31m\]$RET\[\e[0m\]")'
# different color for remote hosts
[[ $SSH_TTY ]] && local HC=$C || local HC=$W
# space goes inside the printf so its not there when there's no git branch
PS1="$TITLEBAR $EMK┌┤$HC\h$EMK->$UC\u$RET_VALUE\$(__git_ps1 ' $G%s$NONE') $EMB\w$EMK$UC\n $EMK└➤$NONE "
export PS4='+($?) $BASH_SOURCE:$FUNCNAME:$LINENO:'
}
# git prompt
if [[ -f /usr/share/git/git-prompt.sh ]]; then
. /usr/share/git/git-prompt.sh
else
__git_ps1() { :; }
fi
# chroot prompt
if [[ -f /.chroot ]]; then
root_name=$(< /.chroot)
root_name=${root_name:-NONAME}
PS1='[\u@\h${root_name} \w]\$ '
return
else
# show return val of last command
PROMPT_COMMAND='RET=$?'
GIT_PS1_SHOWDIRTYSTATE=yes
bash_prompt
unset bash_prompt
fi