summaryrefslogtreecommitdiffstats
path: root/bin/fancy-prompt
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-02-17 15:50:40 -0600
committerJesse Luehrs <doy@tozt.net>2012-02-17 17:29:55 -0600
commit623151a60fc34c4e896e7ce764e5ce55915f92d8 (patch)
tree0d9a793a2619e718c64712a684437cf85a4a9de9 /bin/fancy-prompt
parent31cecdb8b33661f775766ece2c6e2dbe2fab215e (diff)
downloadconf-623151a60fc34c4e896e7ce764e5ce55915f92d8.tar.gz
conf-623151a60fc34c4e896e7ce764e5ce55915f92d8.zip
escape prompt colors properly for readline
Diffstat (limited to 'bin/fancy-prompt')
-rwxr-xr-xbin/fancy-prompt13
1 files changed, 12 insertions, 1 deletions
diff --git a/bin/fancy-prompt b/bin/fancy-prompt
index d9f9809..484b5fc 100755
--- a/bin/fancy-prompt
+++ b/bin/fancy-prompt
@@ -3,6 +3,13 @@
# use strict;
# use warnings;
+# readline gets confused if non-printable characters in prompts aren't escaped
+my $prompt_escape;
+if ($ARGV[0] eq '--prompt-escape') {
+ shift;
+ $prompt_escape = 1;
+}
+
# collect information
chomp(my $hostname = `hostname`);
my $cols = `tput cols`;
@@ -90,7 +97,11 @@ $colornames{battery} = $battery > 40 ? $colornames{background}
: $battery > 15 ? $colornames{battwarn}
: $battery > 5 ? $colornames{battcrit}
: $colornames{battemerg};
-sub color { $colors{$colornames{$_[0]}} }
+sub color {
+ my $code = $colors{$colornames{$_[0]}};
+ $code = '\[' . $code . '\]' if $prompt_escape;
+ $code;
+}
# define some display things
my $border = '-';