From: Amin Bandali Date: Mon, 23 Sep 2019 00:20:13 +0000 (-0400) Subject: bash: update prompt X-Git-Url: https://git.shemshak.org/gitweb.cgi/~bandali/configs/commitdiff_plain/a5c8d5d67e6d214b64d534db2ade19cbf1533532?hp=bae7970cfc520d0203b03eeacc87d521a1b30651 bash: update prompt --- diff --git a/.bashrc b/.bashrc index b5c3480..f7cbfc8 100644 --- a/.bashrc +++ b/.bashrc @@ -22,20 +22,22 @@ if [ -n "$IS_GUIX_SYSTEM" ]; then fi # from https://unix.stackexchange.com/a/55935 -a_prompt() { +b_prompt() { cwd=$(sed -e "s:$HOME:~:" -e "s:\(\.\?[^/]\)[^/]*/:\1/:g" <<<$PWD) printf $cwd } -# Adjust the prompt depending on whether we're in 'guix environment'. -if [ -n "$GUIX_ENVIRONMENT" ] -then - PS1="\u@\h [env] \$(a_prompt)> " + +if [ $(id -u) == "0" ]; then + PS1='`printf "\[\e[1;31m\]\$\[\e[00m\]"` ' else - PS1="\u@\h \$(a_prompt)> " + PS1='\$ ' fi +PS1="`[ -n "$GUIX_ENVIRONMENT" ] && printf \" [env]\"`\n$PS1" +__u='`[ \`id -u\` == "0" ] && printf "\[\e[1;31m\]\u\[\e[00m\]" || printf "\u"`' +PS1="$__u@\h:\w/$PS1" # set terminal title -PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: $(a_prompt)\007"' +PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: $(b_prompt)\007"' # i-beam cursor # echo -e "\033[5 q" # blinking