Browse Source

Revamp bashum color mappings and demo

Finally stop using few-low-lettered globals; use proper Shellfu compliant
naming instead.

Also have separate variables for use in Bash PS*; these need extra chars
for hinting.
Alois Mahdal 5 years ago
parent
commit
bbd598ab23
3 changed files with 75 additions and 33 deletions
  1. 64
    22
      dotfiles/bash/colors.bashrc
  2. 1
    1
      dotfiles/bash/defaults.bashrc
  3. 10
    10
      dotfiles/bash/post.bashrc

+ 64
- 22
dotfiles/bash/colors.bashrc View File

@@ -1,26 +1,68 @@
1 1
 #!/bin/bash
2 2
 
3 3
 # get some fancy colorz
4
-      black="\[\033[0;30m\]"
5
-        red="\[\033[0;31m\]"
6
-      green="\[\033[0;32m\]"
7
-     yellow="\[\033[0;33m\]"
8
-       blue="\[\033[0;34m\]"
9
-    magenta="\[\033[0;35m\]"
10
-       cyan="\[\033[0;36m\]"
11
-      white="\[\033[0;37m\]"
12
-     lblack="\[\033[1;30m\]"
13
-       lred="\[\033[1;31m\]"
14
-     lgreen="\[\033[1;32m\]"
15
-    lyellow="\[\033[1;33m\]"
16
-      lblue="\[\033[1;34m\]"
17
-   lmagenta="\[\033[1;35m\]"
18
-      lcyan="\[\033[1;36m\]"
19
-     lwhite="\[\033[1;37m\]"
20
-     normal="\[\033[1;0m\]"
4
+BASHUM_COLOR_BLACK=$'\033[0;30m'
5
+BASHUM_COLOR_RED=$'\033[0;31m'
6
+BASHUM_COLOR_GREEN=$'\033[0;32m'
7
+BASHUM_COLOR_YELLOW=$'\033[0;33m'
8
+BASHUM_COLOR_BLUE=$'\033[0;34m'
9
+BASHUM_COLOR_MAGENTA=$'\033[0;35m'
10
+BASHUM_COLOR_CYAN=$'\033[0;36m'
11
+BASHUM_COLOR_WHITE=$'\033[0;37m'
12
+BASHUM_COLOR_LBLACK=$'\033[1;30m'
13
+BASHUM_COLOR_LRED=$'\033[1;31m'
14
+BASHUM_COLOR_LGREEN=$'\033[1;32m'
15
+BASHUM_COLOR_LYELLOW=$'\033[1;33m'
16
+BASHUM_COLOR_LBLUE=$'\033[1;34m'
17
+BASHUM_COLOR_LMAGENTA=$'\033[1;35m'
18
+BASHUM_COLOR_LCYAN=$'\033[1;36m'
19
+BASHUM_COLOR_LWHITE=$'\033[1;37m'
20
+BASHUM_COLOR_NORMAL=$'\033[1;0m'
21 21
 
22
-coldemo="colors demo: \n$black  black$red  red$green  green$yellow  yellow"
23
-coldemo="${coldemo}$blue  blue$magenta  magenta$cyan  cyan$white  white\n "
24
-coldemo="${coldemo}$lblack lblack$lred lred$lgreen lgreen$lyellow lyellow"
25
-coldemo="${coldemo}$lblue lblue$lmagenta lmagenta$lcyan lcyan$lwhite lwhite\n"
26
-coldemo="${coldemo}$normal normal\n"
22
+# get some fancy colorz
23
+BASHUM_PS_COLOR_BLACK=$'\[\033[0;30m\]'
24
+BASHUM_PS_COLOR_RED=$'\[\033[0;31m\]'
25
+BASHUM_PS_COLOR_GREEN=$'\[\033[0;32m\]'
26
+BASHUM_PS_COLOR_YELLOW=$'\[\033[0;33m\]'
27
+BASHUM_PS_COLOR_BLUE=$'\[\033[0;34m\]'
28
+BASHUM_PS_COLOR_MAGENTA=$'\[\033[0;35m\]'
29
+BASHUM_PS_COLOR_CYAN=$'\[\033[0;36m\]'
30
+BASHUM_PS_COLOR_WHITE=$'\[\033[0;37m\]'
31
+BASHUM_PS_COLOR_LBLACK=$'\[\033[1;30m\]'
32
+BASHUM_PS_COLOR_LRED=$'\[\033[1;31m\]'
33
+BASHUM_PS_COLOR_LGREEN=$'\[\033[1;32m\]'
34
+BASHUM_PS_COLOR_LYELLOW=$'\[\033[1;33m\]'
35
+BASHUM_PS_COLOR_LBLUE=$'\[\033[1;34m\]'
36
+BASHUM_PS_COLOR_LMAGENTA=$'\[\033[1;35m\]'
37
+BASHUM_PS_COLOR_LCYAN=$'\[\033[1;36m\]'
38
+BASHUM_PS_COLOR_LWHITE=$'\[\033[1;37m\]'
39
+BASHUM_PS_COLOR_NORMAL=$'\[\033[1;0m\]'
40
+
41
+#shellcheck disable=SC1087
42
+bashum__colordemo() {
43
+    local bla=$BASHUM_COLOR_BLACK
44
+    local red=$BASHUM_COLOR_RED
45
+    local gre=$BASHUM_COLOR_GREEN
46
+    local yel=$BASHUM_COLOR_YELLOW
47
+    local blu=$BASHUM_COLOR_BLUE
48
+    local mag=$BASHUM_COLOR_MAGENTA
49
+    local cya=$BASHUM_COLOR_CYAN
50
+    local whi=$BASHUM_COLOR_WHITE
51
+    local lbla=$BASHUM_COLOR_LBLACK
52
+    local lred=$BASHUM_COLOR_LRED
53
+    local lgre=$BASHUM_COLOR_LGREEN
54
+    local lyel=$BASHUM_COLOR_LYELLOW
55
+    local lblu=$BASHUM_COLOR_LBLUE
56
+    local lmag=$BASHUM_COLOR_LMAGENTA
57
+    local lcya=$BASHUM_COLOR_LCYAN
58
+    local lwhi=$BASHUM_COLOR_LWHITE
59
+    local n=$BASHUM_COLOR_NORMAL
60
+    echo "black:   $bla[abc123]$n   lblack: $lbla[abc123]$n"
61
+    echo "red:     $red[abc123]$n     lred: $lred[abc123]$n"
62
+    echo "yellow:  $yel[abc123]$n  lyellow: $lyel[abc123]$n"
63
+    echo "green:   $gre[abc123]$n   lgreen: $lgre[abc123]$n"
64
+    echo "cyan:    $cya[abc123]$n    lcyan: $lcya[abc123]$n"
65
+    echo "blue:    $blu[abc123]$n    lblue: $lblu[abc123]$n"
66
+    echo "magenta: $mag[abc123]$n lmagenta: $lmag[abc123]$n"
67
+    echo "white:   $whi[abc123]$n   lwhite: $lwhi[abc123]$n"
68
+}

+ 1
- 1
dotfiles/bash/defaults.bashrc View File

@@ -10,5 +10,5 @@ __bashum__mkps1user() {
10 10
 }
11 11
 
12 12
 __bashum__mkps1host() {
13
-    echo "$blue\h$normal";
13
+    echo "$BASHUM_PS_COLOR_BLUE\h$BASHUM_PS_COLOR_NORMAL";
14 14
 }

+ 10
- 10
dotfiles/bash/post.bashrc View File

@@ -42,25 +42,25 @@ __bashum__mkps1() {
42 42
     # and ~/.bash/host/*.bashrc
43 43
     test -n "$SSH_CONNECTION" \
44 44
      && echo -n "$(__bashum__mkps1user)"    # username only when on ssh
45
-    echo -n "$lwhite@"                      # nice shiny at sign
45
+    echo -n "$BASHUM_PS_COLOR_LWHITE@"         # nice shiny at sign
46 46
     echo -n "$(__bashum__mkps1host)"        # hostname colored per host
47
-    echo -n "$yellow"                       #\
47
+    echo -n "$BASHUM_PS_COLOR_LYELLOW"         #\
48 48
     echo -n     '$(__bashum__task_context)' # > taskwarrior's context
49
-    echo -n "$normal"                       #/
50
-    echo -n "$lwhite:"                      # nice shiny colon
51
-    echo -n "$lblue\w$normal"               # current workdir
52
-    echo -n "$green"                        #\
49
+    echo -n "$BASHUM_PS_COLOR_NORMAL"          #/
50
+    echo -n "$BASHUM_PS_COLOR_LWHITE:"         # nice shiny colon
51
+    echo -n "$BASHUM_PS_COLOR_BLUE\w$BASHUM_PS_COLOR_NORMAL"   # current workdir
52
+    echo -n "$BASHUM_PS_COLOR_GREEN"           #\
53 53
     echo -n     '$(__git_ps1 "(%s)")'       # > git's PS1
54
-    echo -n "$normal"                       #/
55
-    echo -n "$lred"                         #\
54
+    echo -n "$BASHUM_PS_COLOR_NORMAL"          #/
55
+    echo -n "$BASHUM_PS_COLOR_LRED"            #\
56 56
     echo -n     '$(__bashum__lastrv -r)'    # > last exit status (nothing if zero)
57
-    echo -n "$normal"                       #/
57
+    echo -n "$BASHUM_PS_COLOR_NORMAL"          #/
58 58
     echo '$ '                               # obligatory dollar
59 59
 }
60 60
 
61 61
 #shellcheck disable=SC2154
62 62
 __bashum__mkps2() {
63
-    echo "$lwhite·$blue>$yellow>$white>$normal "
63
+    echo "$BASHUM_PS_COLOR_LWHITE·$BASHUM_PS_COLOR_BLUE>$BASHUM_PS_COLOR_YELLOW>$BASHUM_PS_COLOR_WHITE>$BASHUM_PS_COLOR_NORMAL "
64 64
 }
65 65
 
66 66
 # and use to assemble own PS1