Browse code

ps1.sh: fix ps1_toggle_colors.

It seems bash no longer returns an empty string when accessing a non-existing
hash, e.g. trying to read ${c['red']} after c has been unset leads to:
-bash: 'red': syntax error: operand expected (error token is "'red'")

Xavier G authored on 03/11/2016 12:06:37
Showing 1 changed files
... ...
@@ -10,6 +10,14 @@ function declare_colors {
10 10
 	done
11 11
 }
12 12
 
13
+function disable_colors {
14
+	local cn
15
+	declare -g -A c
16
+	for cn in normal {,bright_}{black,red,green,yellow,blue,magenta,cyan,white}; do
17
+		c["${cn}"]=''
18
+	done
19
+}
20
+
13 21
 # Generate the PS1 variable; doing that in a function allows to reflect almost
14 22
 # anything in the prompt.
15 23
 function generate_ps1 {
... ...
@@ -60,7 +68,8 @@ function ps1_toggle_date {
60 68
 # prompt:
61 69
 function ps1_toggle_colors {
62 70
 	if [ "${PS1_USE_COLORS}" ]; then
63
-		unset PS1_USE_COLORS c
71
+		unset PS1_USE_COLORS
72
+		disable_colors
64 73
 	else
65 74
 		declare_colors
66 75
 		PS1_USE_COLORS='yes'