Browse Source

more sleek colorize() for bashrc

Von Random 1 week ago
parent
commit
c410a8a0a2
1 changed files with 5 additions and 9 deletions
  1. 5
    9
      bashrc

+ 5
- 9
bashrc View File

@@ -16,19 +16,15 @@ export LS_COLORS='no=00:fi=00:di=34:ow=34;40:ln=35:pi=30;44:so=35;44:do=35;44:bd
16 16
 # }}}
17 17
 # {{{ prompt
18 18
 colorize() {
19
-    typeset prompt="$1"; shift
20
-    typeset color_nr="$1"; shift
21
-    if ((prompt)); then
22
-        printf '\[\e[38;5;%sm\]%s\[\e[39m\]' "$color_nr" "$*"
23
-    else
24
-        printf '\e[38;5;%sm%s\e[39m' "$color_nr" "$*"
25
-    fi
19
+    typeset escs prompt="$1" color_nr="$2"; shift 2
20
+    ((prompt)) && escs='\[\e[38;5;%sm\]%s\[\e[39m\]' || escs='\e[38;5;%sm%s\e[39m'
21
+    printf "$escs" "$color_nr" "$*"
26 22
 }
27 23
 prompt_command() {
28 24
     typeset cwd=$(colorize 1 8 "$(pwd)")
29 25
     case "$TERM" in
30
-        (screen*) printf '\033k%s\033\'  "${HOSTNAME%%.*}";;
31
-        (*)       printf '\033]0;%s\007' "${HOSTNAME%%.*}";;
26
+        (screen*) printf '\ek%s\e\'  "${HOSTNAME%%.*}";;
27
+        (*)       printf '\e]0;%s\a' "${HOSTNAME%%.*}";;
32 28
     esac
33 29
     PS1="[ bash-\\v | $ps_user $HOSTNAME:$cwd ]\\n$ps_bang "
34 30
 }

Loading…
Cancel
Save