1
0
Fork 0

bash color escapes into variables

This commit is contained in:
Von Random 2014-11-16 05:15:26 +03:00
parent 66f4e7dcc7
commit e41b04ef2c

31
shellrc
View file

@ -279,36 +279,33 @@ else
extras=( "${HOME}/.bashrc.extras" ) extras=( "${HOME}/.bashrc.extras" )
# }}} # }}}
# {{{ prompt # {{{ prompt
# Color escapes description colors=('black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white')
# color escape looks like \[\e[x;3ym\] for i in {0..7}; do
# background escape looks like \[\e[4ym\] eval "n${colors[$i]}='\[\e[0;3${i}m\]'"
# style reset escape is \[\e[0m\] eval "b${colors[$i]}='\[\e[1;3${i}m\]'"
# x is style: done
# 0 - regular, 1 - bold, 4 - underlined reset='\[\e[0m\]'
# y is color: lb="${byellow}[${reset}"
# 0 - Black, 1 - Red, 2 - Green, 3 - Yellow rb="${byellow}]${reset}"
# 4 - Blue, 5 - Magenta, 6 - Cyan, 7 - White bb="${byellow} ${reset}"
lb='\[\e[1;33m\][\[\e[0m\]'
rb='\[\e[1;33m\]]\[\e[0m\]'
bb='\[\e[1;33m\] \[\e[0m\]'
prompt_host='\h' prompt_host='\h'
prompt_bang='\$\[\e[0m\]' prompt_bang="\$${reset}"
precmd() { precmd() {
if [[ -z ${hide_info} ]]; then if [[ -z ${hide_info} ]]; then
prompt_cwd="\[\e[1;37m\]${PWD}\[\e[0m\]" prompt_cwd="${bwhite}${PWD}${reset}"
if [[ ${UID} -eq 1000 || ${UID} -eq 1205 ]]; then if [[ ${UID} -eq 1000 || ${UID} -eq 1205 ]]; then
prompt_user='' prompt_user=''
else else
prompt_user='\[\e[1;31m\]\u\[\e[1;33m\]@\[\e[0m\]' prompt_user="${bred}\u${byellow}@${reset}"
fi fi
prompt_info="${lb}${prompt_user}${prompt_host}${bb}${prompt_cwd}${rb}${lb}bash-\v${rb}${newline}" prompt_info="${lb}${prompt_user}${prompt_host}${bb}${prompt_cwd}${rb}${lb}bash-\v${rb}${newline}"
else else
prompt_info='' prompt_info=''
fi fi
if [[ $UID -eq 0 ]]; then if [[ $UID -eq 0 ]]; then
prompt_bang_color='\[\e[1;31m\]' prompt_bang_color="${bred}"
else else
prompt_bang_color='\[\e[1;32m\]' prompt_bang_color="${bgreen}"
fi fi
PS1="${prompt_info}${prompt_bang_color}${prompt_bang} " PS1="${prompt_info}${prompt_bang_color}${prompt_bang} "
} }