-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path98-prompt.bash
68 lines (54 loc) · 1.76 KB
/
98-prompt.bash
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
if [[ -f /usr/share/git/git-prompt.sh ]]; then
# shellcheck disable=SC1091
source /usr/share/git/git-prompt.sh
fi
PROMPT_COMMAND=__prompt_command
__prompt_command() {
local last_exit_status="$?"
local ansi_fg_default='\[\033[39m\]'
local ansi_fg_red='\[\033[31m\]'
local ansi_fg_green='\[\033[32m\]'
local ansi_fg_yellow='\[\033[33m\]'
local ansi_fg_blue='\[\033[34m\]'
local ansi_fg_purple='\[\033[35m\]'
local ansi_fg_cyan='\[\033[36m\]'
local ansi_dim_on='\[\033[2m\]'
local ansi_reset='\[\033[0m\]'
PS1="${ansi_dim_on}"
if [[ ${last_exit_status} != 0 ]]; then
PS1+="=> ${ansi_fg_red}${last_exit_status}${ansi_fg_default}\n"
fi
PS1+="\u@\h:\w"
local infos
infos=()
if [[ -n $IN_NIX_SHELL ]]; then
if test "${DEVBOX_SHELL_ENABLED}" = "1"; then
infos+=("env:${ansi_fg_blue}devbox${ansi_fg_default}")
else
infos+=("env:${ansi_fg_cyan}nix${ansi_fg_default}")
fi
fi
if [[ -n $VIRTUAL_ENV ]]; then
infos+=("env:${ansi_fg_yellow}venv${ansi_fg_default}")
fi
local git_branch
git_branch=$(__git_ps1 | sed s/[\(\)\ ]//g)
if [[ -n $git_branch ]]; then
if [[ $git_branch == *"main"* ]] || [[ $git_branch == *"master"* ]] || [[ $git_branch == *"trunk"* ]]; then
git_branch="${ansi_fg_red}${git_branch}${ansi_fg_default}"
fi
infos+=("git:${git_branch}")
fi
if [[ ${#infos[@]} -gt 0 ]]; then
PS1+=" ["
for i in "${infos[@]}"; do
PS1+=" ${i}"
done
PS1+=" ]"
fi
PS1+="\n"
PS1+="${ansi_dim_on}" # workaround for broken ansi state (lost ansi flags prior to last newline) on window resize
PS1+='$'
PS1+="${ansi_reset}"
PS1+=" "
}