about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-06-15 15:27:59 -0500
committerCase Duckworth2022-06-15 15:27:59 -0500
commit8a209c2fa33889f36f27c4af55e4ba9429fcd98a (patch)
tree644449102e692adbee590c48bc765776c084d741
parentMerge branch 'main' of github.com:duckwork/etc (diff)
downloadetc-8a209c2fa33889f36f27c4af55e4ba9429fcd98a.tar.gz
etc-8a209c2fa33889f36f27c4af55e4ba9429fcd98a.zip
Change bash prompt
-rw-r--r--bash/prompt.bash56
1 files changed, 30 insertions, 26 deletions
diff --git a/bash/prompt.bash b/bash/prompt.bash index f1bdd69..15fdb41 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash
@@ -1,38 +1,42 @@
1# bash prompt 1# bash prompt
2 2
3PS1= 3if [[ -n "$INSIDE_EMACS" ]]; then
4 PS1=" \n\[\e[34m\]\$ \[\e[0m\]"
5else
6 PS1=
4 7
5# user, host, and cwd 8 # user, host, and cwd
6PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') 9 PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...')
7PS1+='\[\e[0;46m\]\u@\h \w' 10 PS1+='\[\e[0;46m\]\u@\h \w'
8 11
9# git bit 12 # git bit
10# see https://unix.stackexchange.com/questions/278206 13 # see https://unix.stackexchange.com/questions/278206
11possible_git_prompt_locations=( 14 possible_git_prompt_locations=(
12 /usr/share/git/git-prompt.sh # Arch, etc. (default?) 15 /usr/share/git/git-prompt.sh # Arch, etc. (default?)
13 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... 16 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ...
14 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? 17 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ??
15 # I have yet to find Alpine's git prompt location. 18 # I have yet to find Alpine's git prompt location.
16) 19 )
17 20
18for file in "${possible_git_prompt_locations[@]}"; do 21 for file in "${possible_git_prompt_locations[@]}"; do
19 if [[ -f "$file" ]]; then 22 if [[ -f "$file" ]]; then
20 source "$file" && 23 source "$file" &&
21 PS1+='\[\e[35m\]$(__git_ps1)' 24 PS1+='\[\e[35m\]$(__git_ps1)'
22 break 25 break
23 fi 26 fi
24done 27 done
25 28
26# newline 29 # newline
27PS1+='\[\e[0m\]\n' 30 PS1+='\[\e[0m\]\n'
28 31
29# exit code (only if error) 32 # exit code (only if error)
30__prompt_exit_code() { 33 __prompt_exit_code() {
31 local ec=$? 34 local ec=$?
32 (( $ec > 0 )) && 35 (( $ec > 0 )) &&
33 printf "$ec" 36 printf "$ec"
34} 37 }
35PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' 38 PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]'
36 39
37# delimiter 40 # delimiter
38PS1+='; ' 41 PS1+='; '
42fi