diff options
author | Case Duckworth | 2023-01-30 12:24:02 -0600 |
---|---|---|
committer | Case Duckworth | 2023-01-30 12:24:02 -0600 |
commit | ff41d9acc805099f27f1cf060ca9db72d2fdb74f (patch) | |
tree | f3831f08979bd1395fc4c737ade866e13700df3b /bash/prompt.bash | |
parent | meh. (diff) | |
download | etc-ff41d9acc805099f27f1cf060ca9db72d2fdb74f.tar.gz etc-ff41d9acc805099f27f1cf060ca9db72d2fdb74f.zip |
Bash!
Diffstat (limited to 'bash/prompt.bash')
-rw-r--r-- | bash/prompt.bash | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/bash/prompt.bash b/bash/prompt.bash index 06ca638..f09d3ab 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash | |||
@@ -1,8 +1,32 @@ | |||
1 | # bash prompt | 1 | # bash prompt |
2 | 2 | ||
3 | if [[ -n "$INSIDE_EMACS" ]]; then | 3 | MY_BASH_PROMPT=smiley_prompt |
4 | PS1="\n\[\e[34m\]\$ \[\e[0m\]" | 4 | |
5 | else | 5 | # terminal title (current directory) |
6 | __prompt_term_title() { # __prompt_term_title TITLE... | ||
7 | printf '\033]0;%s\007\n' "$*" | ||
8 | } | ||
9 | |||
10 | __prompt_exit_code() { # __prompt_exit_code CODES... | ||
11 | # Each CODE is of the form N=STR. If the code doesn't match one of CODES, | ||
12 | # its number will be printed. | ||
13 | local ec=$? | ||
14 | for code; do | ||
15 | if ((ec == ${code%=*})); then | ||
16 | printf '%s\n' "${code#*=}" | ||
17 | return | ||
18 | elif ((ec == 0)) && [[ "${code%=*}" = ok ]]; then | ||
19 | printf '%s\n' "${code#*=}" | ||
20 | return | ||
21 | elif ((ec > 0)) && [[ "${code%=*}" = fail ]]; then | ||
22 | printf '%s\n' "${code#*=}" | ||
23 | return | ||
24 | fi | ||
25 | done | ||
26 | printf '%s\n' "$ec" | ||
27 | } | ||
28 | |||
29 | two_line_prompt() { | ||
6 | PS1= | 30 | PS1= |
7 | 31 | ||
8 | # user, host, and cwd | 32 | # user, host, and cwd |
@@ -21,7 +45,7 @@ else | |||
21 | for file in "${possible_git_prompt_locations[@]}"; do | 45 | for file in "${possible_git_prompt_locations[@]}"; do |
22 | if [[ -f "$file" ]]; then | 46 | if [[ -f "$file" ]]; then |
23 | source "$file" && | 47 | source "$file" && |
24 | PS1+='\[\e[35m\]$(__git_ps1)' | 48 | PS1+='\[\e[0m\]\[\e[35m\]$(__git_ps1)' |
25 | break | 49 | break |
26 | fi | 50 | fi |
27 | done | 51 | done |
@@ -29,20 +53,18 @@ else | |||
29 | # newline | 53 | # newline |
30 | PS1+='\[\e[0m\]\n' | 54 | PS1+='\[\e[0m\]\n' |
31 | 55 | ||
32 | # exit code (only if error) | 56 | PS1+='\[\e[31m\]$(__prompt_exit_code 0=)\[\e[0m\]' |
33 | __prompt_exit_code() { | ||
34 | local ec=$? | ||
35 | (($ec > 0)) && | ||
36 | printf "$ec" | ||
37 | } | ||
38 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' | ||
39 | |||
40 | # terminal title (current directory) | ||
41 | __prompt_term_title() { | ||
42 | printf '\033]0;%s\007\n' "$*" | ||
43 | } | ||
44 | PS1+='\[$(__prompt_term_title "$USER@$(hostname): $PWD")\]' | 57 | PS1+='\[$(__prompt_term_title "$USER@$(hostname): $PWD")\]' |
45 | 58 | ||
46 | # delimiter | 59 | # delimiter |
47 | PS1+='; ' | 60 | PS1+='; ' |
48 | fi | 61 | } |
62 | |||
63 | smiley_prompt() { | ||
64 | __prompt_ec() { case $? in 0) echo '^_^' ;; *) echo ';_;' ;; esac } | ||
65 | PS1='\[\e[1m\]$(__prompt_exit_code "ok=^_^" "fail=;_;") \w\[\e[0m\] ' | ||
66 | PS1+='\[$(__prompt_term_title "$USER@$(hostname): $PWD")\]' | ||
67 | PS1+='\$ ' | ||
68 | } | ||
69 | |||
70 | eval "$MY_BASH_PROMPT" | ||