You are not logged in.
Hi, what I'm trying to achieve is a bash prompt that is pretty default (user@host current-directory) but, the current directory must be shown in red if the last command was unsucessful, green otherwise.
This is in my .bashrc
if [ $(tput colors) -gt 0 ] ; then
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
RST=$(tput op)
fi
bash_prompt_command() {
last_exit=$?
exit_to_color=$(exit_to_color $last_exit)
}
export PROMPT_COMMAND=bash_prompt_command
exit_to_color() {
[ $1 == 0 ] && echo $GREEN || echo $RED
}
PS1="\u@\h \$exit_to_color\W\[$RST\] \$"
The color thingie works, but sometimes \W doesn't show anything at all. example:
dieter@dieter-mbp ~ $pwd
/home/dieter
dieter@dieter-mbp ~ $cd .reference/
dieter@dieter-mbp .reference $cd
dieter@dieter-mbp ~ $cd workspaces/
dieter@dieter-mbp $pwd
/home/dieter/workspaces
dieter@dieter-mbp $
Also, sometimes I see 'leftovers' from the previous command on my prompt, if I use bash history functions and I can't erase them.
dieter@dieter-mbp ~ $svn diff workspaces/eclipse/tools/scripts/cdnbench.php >/dev/null
dieter@dieter-mbp ~ $svn d #<--- what I did here is press up arrow (shows previous command perfectly), and then down arrow (doesn't clean up everything)
Note that it's just a visual artifact, not a functional one:
dieter@dieter-mbp ~ $svn diff workspaces/eclipse/tools/scripts/cdnbench.php >/dev/null
dieter@dieter-mbp ~ $svn decho ok
ok
dieter@dieter-mbp ~ $ # if i press up arrow at this point, it shows the previous command 'echo ok', pressing down works fine too
Any ideas?
Last edited by Dieter@be (2008-10-13 18:36:44)
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
Try disabling the colour effects and see if that clears up the problem. It may be interfering with your prompt.
M*cr*s*ft: Who needs quality when you have marketing?
Offline
Well, when I do that (I change the PROMPT_COMMAND to 'true' instead of 'bash_prompt_command'), then the 'leftover from previous command' artifact is gone. However the '\W' sometimes empty is exactly the same.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
You need to escape color codes with \[ \] or it will count them as printing characters, hence the visual offset.
[git] | [AURpkgs] | [arch-games]
Offline
You need to escape color codes with \[ \] or it will count them as printing characters, hence the visual offset.
Thanks a lot !
Changed it to
PS1="\u@\h \[\$exit_to_color\]\W\[$RST\] \$"
works like a charm now
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline