bash: set_color helper (bash 3+4)

This commit is contained in:
Loic Nageleisen 2014-12-04 16:08:08 +01:00
parent e22a871ede
commit 5c386aa52d
5 changed files with 241 additions and 116 deletions

25
bash/ansi Normal file
View file

@ -0,0 +1,25 @@
if [[ $BASH_VERSINFO -gt 3 ]]; then
source "$DOTFILES_BASH_DIR"/ansi4
else
source "$DOTFILES_BASH_DIR"/ansi3
fi
setup_ansi_sgr_index
# set_color [-p] color
# -p: wraps output for bash prompt size match
set_color() {
if [[ $1 == "-p" ]]; then
local prompt=1
shift
fi
local code=$1
[[ $prompt -eq 1 ]] && echo -n "\["
echo -n "\033["
ansi_sgr "$code"
echo -n "m"
[[ $prompt -eq 1 ]] && echo -n "\]"
}
# vim: ft=sh