feat(bash): improve prompt

This commit is contained in:
buffet 2023-11-28 09:53:06 +01:00
parent 47a42ceacd
commit 9bb97c3706

View file

@ -16,34 +16,34 @@ update() {
} }
__prompt() { __prompt() {
local status="$?" local status="$?"
local row local row
local col local col
IFS=';' read -rs -dR -p $'\e[6n' row col >/dev/tty IFS=';' read -rs -dR -p $'\e[6n' row col >/dev/tty
if [[ $col != 1 ]]; then if [[ $col != 1 ]]; then
printf '%s' $'\e[0;7m%\n\e[0m' printf '%s' $'\e[0;7m%\n\e[0m'
fi fi
PS1='\[\e[0;1m\][' PS1='\[\e[0;1m\]['
case $status in case $status in
0) PS1+='\[\e[32m\]' ;; 0) PS1+='\[\e[32m\]' ;;
*) PS1+='\[\e[31m\]' ;; *) PS1+='\[\e[31m\]' ;;
esac esac
if [[ "$PWD" == "$HOME" ]]; then if [[ "$PWD" == "$HOME" ]]; then
PS1+="~" PS1+="~"
elif [[ "$PWD" == / ]]; then elif [[ "$PWD" == / ]]; then
PS1+=/ PS1+=/
else else
PS1+="${PWD##*/}" PS1+="${PWD##*/}"
fi fi
PS1+='\[\e[0;1m\]]\[\e[0m\]' PS1+='\[\e[0;1m\]]\[\e[0m\]'
[[ $CONTAINER_ID ]] && PS1+="'" [[ $CONTAINER_ID ]] && PS1+="'"
PS1+=' ' PS1+=' '
} }
PROMPT_COMMAND=__prompt PROMPT_COMMAND=__prompt