Debian Codegraph @

bash-profile.snippet

raw
1 # From Andrzej Szelachowski's ~/.bash_profile:
2
3
4 # Note that a variable may require special treatment
5 #+ if it will be exported.
6
7 DARKGRAY='\e[1;30m'
8 LIGHTRED='\e[1;31m'
9 GREEN='\e[32m'
10 YELLOW='\e[1;33m'
11 LIGHTBLUE='\e[1;34m'
12 NC='\e[m'
13
14 PCT="\`if [[ \$EUID -eq 0 ]]; then T='$LIGHTRED' ; else T='$LIGHTBLUE'; fi;
15 echo \$T \`"
16
17 # For "literal" command substitution to be assigned to a variable,
18 #+ use escapes and double quotes:
19 #+ PCT="\` ... \`" . . .
20 # Otherwise, the value of PCT variable is assigned only once,
21 #+ when the variable is exported/read from .bash_profile,
22 #+ and it will not change afterwards even if the user ID changes.
23
24
25 PS1="\n$GREEN[\w] \n$DARKGRAY($PCT\t$DARKGRAY)-($PCT\u$DARKGRAY)-($PCT\!
26 $DARKGRAY)$YELLOW-> $NC"
27
28 # Escape a variables whose value changes:
29 # if [[ \$EUID -eq 0 ]],
30 # Otherwise the value of the EUID variable will be assigned only once,
31 #+ as above.
32
33 # When a variable is assigned, it should be called escaped:
34 #+ echo \$T,
35 # Otherwise the value of the T variable is taken from the moment the PCT
36 #+ variable is exported/read from .bash_profile.
37 # So, in this example it would be null.
38
39 # When a variable's value contains a semicolon it should be strong quoted:
40 # T='$LIGHTRED',
41 # Otherwise, the semicolon will be interpreted as a command separator.
42
43
44 # Variables PCT and PS1 can be merged into a new PS1 variable:
45
46 PS1="\`if [[ \$EUID -eq 0 ]]; then PCT='$LIGHTRED';
47 else PCT='$LIGHTBLUE'; fi;
48 echo '\n$GREEN[\w] \n$DARKGRAY('\$PCT'\t$DARKGRAY)-\
49 ('\$PCT'\u$DARKGRAY)-('\$PCT'\!$DARKGRAY)$YELLOW-> $NC'\`"
50
51 # The trick is to use strong quoting for parts of old PS1 variable.