diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-02-17 15:50:40 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-02-17 17:29:55 -0600 |
commit | 623151a60fc34c4e896e7ce764e5ce55915f92d8 (patch) | |
tree | 0d9a793a2619e718c64712a684437cf85a4a9de9 | |
parent | 31cecdb8b33661f775766ece2c6e2dbe2fab215e (diff) | |
download | conf-623151a60fc34c4e896e7ce764e5ce55915f92d8.tar.gz conf-623151a60fc34c4e896e7ce764e5ce55915f92d8.zip |
escape prompt colors properly for readline
-rw-r--r-- | bashrc | 2 | ||||
-rwxr-xr-x | bin/fancy-prompt | 13 |
2 files changed, 13 insertions, 2 deletions
@@ -205,7 +205,7 @@ else export PROMPT_COMMAND="${PROMPT_COMMAND};history -a" fi # prompt {{{ -export PROMPT_COMMAND="__err=\$?;$PROMPT_COMMAND;PS1=\"\$(fancy-prompt "\$__err")\"" +export PROMPT_COMMAND="__err=\$?;$PROMPT_COMMAND;PS1=\"\$(fancy-prompt --prompt-escape "\$__err")\"" # }}} # set the correct perl {{{ if type -a perlbrew > /dev/null 2>&1; then 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 = '-'; |