about summary refs log tree commit diff stats
path: root/bash/prompt.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/prompt.bash')
-rw-r--r--bash/prompt.bash80
1 files changed, 43 insertions, 37 deletions
diff --git a/bash/prompt.bash b/bash/prompt.bash index 15fdb41..06ca638 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash
@@ -1,42 +1,48 @@
1# bash prompt 1# bash prompt
2 2
3if [[ -n "$INSIDE_EMACS" ]]; then 3if [[ -n "$INSIDE_EMACS" ]]; then
4 PS1=" \n\[\e[34m\]\$ \[\e[0m\]" 4 PS1="\n\[\e[34m\]\$ \[\e[0m\]"
5else 5else
6 PS1= 6 PS1=
7 7
8 # user, host, and cwd 8 # user, host, and cwd
9 PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') 9 PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...')
10 PS1+='\[\e[0;46m\]\u@\h \w' 10 PS1+='\[\e[0;46m\]\u@\h \w'
11 11
12 # git bit 12 # git bit
13 # see https://unix.stackexchange.com/questions/278206 13 # see https://unix.stackexchange.com/questions/278206
14 possible_git_prompt_locations=( 14 possible_git_prompt_locations=(
15 /usr/share/git/git-prompt.sh # Arch, etc. (default?) 15 /usr/share/git/git-prompt.sh # Arch, etc. (default?)
16 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... 16 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ...
17 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? 17 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ??
18 # I have yet to find Alpine's git prompt location. 18 # I have yet to find Alpine's git prompt location.
19 ) 19 )
20 20
21 for file in "${possible_git_prompt_locations[@]}"; do 21 for file in "${possible_git_prompt_locations[@]}"; do
22 if [[ -f "$file" ]]; then 22 if [[ -f "$file" ]]; then
23 source "$file" && 23 source "$file" &&
24 PS1+='\[\e[35m\]$(__git_ps1)' 24 PS1+='\[\e[35m\]$(__git_ps1)'
25 break 25 break
26 fi 26 fi
27 done 27 done
28 28
29 # newline 29 # newline
30 PS1+='\[\e[0m\]\n' 30 PS1+='\[\e[0m\]\n'
31 31
32 # exit code (only if error) 32 # exit code (only if error)
33 __prompt_exit_code() { 33 __prompt_exit_code() {
34 local ec=$? 34 local ec=$?
35 (( $ec > 0 )) && 35 (($ec > 0)) &&
36 printf "$ec" 36 printf "$ec"
37 } 37 }
38 PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' 38 PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]'
39 39
40 # delimiter 40 # terminal title (current directory)
41 PS1+='; ' 41 __prompt_term_title() {
42 printf '\033]0;%s\007\n' "$*"
43 }
44 PS1+='\[$(__prompt_term_title "$USER@$(hostname): $PWD")\]'
45
46 # delimiter
47 PS1+='; '
42fi 48fi