mirror of https://github.com/tLDP/LDP
52 lines
1.6 KiB
Plaintext
52 lines
1.6 KiB
Plaintext
# From Andrzej Szelachowski's ~/.bash_profile:
|
|
|
|
|
|
# Note that a variable may require special treatment
|
|
#+ if it will be exported.
|
|
|
|
DARKGRAY='\e[1;30m'
|
|
LIGHTRED='\e[1;31m'
|
|
GREEN='\e[32m'
|
|
YELLOW='\e[1;33m'
|
|
LIGHTBLUE='\e[1;34m'
|
|
NC='\e[m'
|
|
|
|
PCT="\`if [[ \$EUID -eq 0 ]]; then T='$LIGHTRED' ; else T='$LIGHTBLUE'; fi;
|
|
echo \$T \`"
|
|
|
|
# For "literal" command substitution to be assigned to a variable,
|
|
#+ use escapes and double quotes:
|
|
#+ PCT="\` ... \`" . . .
|
|
# Otherwise, the value of PCT variable is assigned only once,
|
|
#+ when the variable is exported/read from .bash_profile,
|
|
#+ and it will not change afterwards even if the user ID changes.
|
|
|
|
|
|
PS1="\n$GREEN[\w] \n$DARKGRAY($PCT\t$DARKGRAY)-($PCT\u$DARKGRAY)-($PCT\!
|
|
$DARKGRAY)$YELLOW-> $NC"
|
|
|
|
# Escape a variables whose value changes:
|
|
# if [[ \$EUID -eq 0 ]],
|
|
# Otherwise the value of the EUID variable will be assigned only once,
|
|
#+ as above.
|
|
|
|
# When a variable is assigned, it should be called escaped:
|
|
#+ echo \$T,
|
|
# Otherwise the value of the T variable is taken from the moment the PCT
|
|
#+ variable is exported/read from .bash_profile.
|
|
# So, in this example it would be null.
|
|
|
|
# When a variable's value contains a semicolon it should be strong quoted:
|
|
# T='$LIGHTRED',
|
|
# Otherwise, the semicolon will be interpreted as a command separator.
|
|
|
|
|
|
# Variables PCT and PS1 can be merged into a new PS1 variable:
|
|
|
|
PS1="\`if [[ \$EUID -eq 0 ]]; then PCT='$LIGHTRED';
|
|
else PCT='$LIGHTBLUE'; fi;
|
|
echo '\n$GREEN[\w] \n$DARKGRAY('\$PCT'\t$DARKGRAY)-\
|
|
('\$PCT'\u$DARKGRAY)-('\$PCT'\!$DARKGRAY)$YELLOW-> $NC'\`"
|
|
|
|
# The trick is to use strong quoting for parts of old PS1 variable.
|