bash: improvements to prompt
This commit is contained in:
parent
3b28bc4ff5
commit
1ae2422a6b
1 changed files with 70 additions and 27 deletions
55
.bashrc
55
.bashrc
|
@ -22,11 +22,11 @@ export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-"$HOME/.config"
|
|||
|
||||
# Change the window title of X terminals
|
||||
case ${TERM} in
|
||||
xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*)
|
||||
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"'
|
||||
(screen*)
|
||||
PROMPT_COMMAND=('echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"')
|
||||
;;
|
||||
screen*)
|
||||
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\033\\"'
|
||||
(xterm*|rxvt*|Eterm*|aterm|kterm|gnome*|interix|konsole*|*)
|
||||
PROMPT_COMMAND=('echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/\~}\007"')
|
||||
;;
|
||||
esac
|
||||
|
||||
|
@ -49,6 +49,7 @@ match_lhs=""
|
|||
if ${use_color} ; then
|
||||
# Enable colors for ls, etc. Prefer ~/.dir_colors #64489
|
||||
if type -P dircolors >/dev/null ; then
|
||||
# shellcheck disable=SC2046
|
||||
if [[ -f ~/.dir_colors ]] ; then
|
||||
eval $(dircolors -b ~/.dir_colors)
|
||||
elif [[ -f /etc/DIR_COLORS ]] ; then
|
||||
|
@ -56,12 +57,54 @@ if ${use_color} ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# given a list of colors, make variables called `col_COLOR`
|
||||
# $@ - the color list (color=number)
|
||||
# $color_mod - a modifier to apply to the color (01 = bold, 00 = nothing)
|
||||
make_colors() {
|
||||
for a; do
|
||||
local -- cname="col_${a%%=*}${modname:+_}${modname:-}"
|
||||
local -- val="${a#*=}"
|
||||
local -- ccode="${val}"
|
||||
declare -g "$cname"='['"$ccode"m
|
||||
# declare -p "$cname"
|
||||
done
|
||||
}
|
||||
|
||||
# set prompt (see: man bash -> search for '^PROMPTING')
|
||||
|
||||
make_colors \
|
||||
red=31 green=32 yellow=33 blue=34 purple=35 turquoise=36 white=38 white=37 \
|
||||
normal=00 bold=01 quiet=02 italic=03 under=04 bg=07 gone=08 strike=09
|
||||
col_end='(B[m'
|
||||
# shellcheck disable=SC2154
|
||||
if [[ ${EUID} == 0 ]] ; then
|
||||
PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
|
||||
# shellcheck disable=
|
||||
ps1_color1="$col_bold$col_red"
|
||||
ps1_color2="$col_bold$col_blue"
|
||||
host='\h'
|
||||
else
|
||||
PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] '
|
||||
ps1_color1="$col_bold$col_green"
|
||||
ps1_color2="$col_bold$col_white"
|
||||
host='\u@\h'
|
||||
fi
|
||||
|
||||
PS1='$ps1_color1['$host'$ps1_color2 \W$ps1_color1]$status\$$col_end '
|
||||
|
||||
# assign $status to the exit code of the previous command, color it white on failure
|
||||
fmt_exit_status() {
|
||||
# status=$?
|
||||
case $? in
|
||||
(0)
|
||||
status=" "
|
||||
;;
|
||||
(*)
|
||||
status="$col_normal$col_white$?$ps1_color1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
PROMPT_COMMAND+=("fmt_exit_status")
|
||||
|
||||
|
||||
else
|
||||
if [[ ${EUID} == 0 ]] ; then
|
||||
# show root@ when we don't have colors
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue