How can I use these red and green arrow signs in the bash prompt?
update 1
This is my .bashrc
file
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[00m\]\
[\033[01;34m\]→ \w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}→ \w\$ '
fi
unset color_prompt force_color_prompt
I want this arrow to be colored as @dessert answered before
(turn red and green for false and true command )
Best Answer
You can use
bash
’sPROMPT_COMMAND
to run a function which builds your prompt, e.g.:Add this code to your
~/.bashrc
file and open a new terminal or run. ~/.bashrc
in an existing one for the changes to take effect. Note that I added the usual\$
at the end, this prints$
normally and#
if you’re root, thus preventing you from running commands as root unwittingly. Thefalse
command is a good way to test the non-zero exit code variant:If you’re into prompt themeing you should definitely take a look at the
zsh
shell (packagezsh
), whose famous configuration framework Oh My Zsh alone comes with over hundred themes. Additionally there are many other plugins available, for example the Spaceship ZSH prompt.Links