-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.shlib
38 lines (32 loc) · 971 Bytes
/
prompt.shlib
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
function ps1-root() {
local ps1_root="\u:$(id -gn)@\h[$(arch)]:\w"
local rev_spec=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ "${rev_spec}" == 'HEAD' ]
then
rev_spec=$(git describe --tags 2>/dev/null)
fi
if [ "${rev_spec}" == 'HEAD' -o -z "${rev_spec}" ]
then
rev_spec=$(git rev-parse HEAD 2>/dev/null | sed -e 's|^\([0-9a-f]\{8\}\).*|\1|')
fi
if [ -n "${rev_spec}" ]
then
ps1_root="${ps1_root}ᚴ${rev_spec}"
fi
echo "${ps1_root}"
}
if [ "${TERM}" = 'screen' -o "${TERM:0:5}" = 'xterm' ]
then
function prompt-command() {
local ps1="$(ps1-root)"
export PS1="${ps1}> \[\e]0;${ps1}\a\]"
export PS2=" "
}
else
function prompt-command() {
local ps1="$(ps1-root)"
export PS1="${ps1}> "
export PS2=" "
}
fi
export PROMPT_COMMAND="export-defs;direnv-reset-def;_direnv_hook;history -a;direnv-set-def;history -r;prompt-command"