diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/prompt.bash | 56 |
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 | ||
3 | PS1= | 3 | if [[ -n "$INSIDE_EMACS" ]]; then |
4 | PS1="\n\[\e[34m\]\$ \[\e[0m\]" | ||
5 | else | ||
6 | PS1= | ||
4 | 7 | ||
5 | # user, host, and cwd | 8 | # user, host, and cwd |
6 | 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 '...') |
7 | PS1+='\[\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 |
11 | possible_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 | ||
18 | for 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 |
24 | done | 27 | done |
25 | 28 | ||
26 | # newline | 29 | # newline |
27 | PS1+='\[\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 | } |
35 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' | 38 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' |
36 | 39 | ||
37 | # delimiter | 40 | # delimiter |
38 | PS1+='; ' | 41 | PS1+='; ' |
42 | fi | ||