-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bash_prompt
More file actions
33 lines (29 loc) · 1.05 KB
/
.bash_prompt
File metadata and controls
33 lines (29 loc) · 1.05 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
#!/usr/bin/env bash
# assume terminal supports ANSI esc-codes
last_exit() {
local e=$?
# inlining args breaks the prompt
[ $e -ne 0 ] && printf "${1:-}%02x${2:-}" $e
return $e
}
# bold; red exit; magenta jobs; blue WD to match `ls`
PS1='\n\[\e[1m\]${ last_exit "\[\e[31m\]" "\[\e[0;1m\] "; }${ [ \j -gt 0 ] && echo "\[\e[35m\]\j\[\e[0;1m\] "; }\[\e[34m\]\w\[\e[0;1m\]'
if command -v git >/dev/null; then
# ⚡ fast O(1) commit-ish
g_c_name() {
# WARN: undocumented behavior!
# exit-code is assumed to be 0, even in `.git/` (bare or not).
git rev-parse --is-inside-work-tree &>/dev/null || return
echo " ${1:-}${
git symbolic-ref --quiet --no-recurse --short HEAD 2>/dev/null || \
git describe --all --exact-match HEAD 2>/dev/null || \
git rev-parse --short HEAD 2>/dev/null || \
echo '?'
}${2:-}"
}
# yellow, because Git is orange, and it complements blue
PS1+='${ g_c_name "\[\e[33m\]" "\[\e[0;1m\]"; }'
fi
PS1+='\n\[\e[1m\]Δ \[\e[0m\]'
# terminals struggle styling across lines:
# https://github.com/mathiasbynens/dotfiles/issues/930