-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.shlib
More file actions
53 lines (45 loc) · 1.4 KB
/
prompt.shlib
File metadata and controls
53 lines (45 loc) · 1.4 KB
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
# shellcheck source=bash-mock/bash-inject.shlib
source "$(dirname "${BASH_SOURCE[0]}")/bash-mock/bash-inject.shlib"
@inject git
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 [ -n "${rev_spec}" ] && [ "${rev_spec}" != 'HEAD' ]
then
local parent_dir
parent_dir="$(basename "$(dirname "$(git rev-parse --show-toplevel 2>/dev/null)")")"
if [ "${rev_spec}" == "${parent_dir}" ]
then
rev_spec=''
fi
else
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
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"