vo0fma
Last Updated: May 02, 2019
·
2.944K
· vsviridov

Sudo-aware shell prompt

LOGNAME=$(logname)
UUSER=$([ "${LOGNAME}" = "${USER}" ] && echo ${USER} || echo '$(tput setaf 1)${LOGNAME}$(tput sgr0) as ${USER}')
PS1="[${UUSER}@\h \W]\\$ "

Find a section of your global bashrc, responsible for setting the prompt and modify the PS1 part, replacing \u with ${UUSER}.

Next time you sudo - it will tell you that you are impersonating.

Picture

3 Responses
Add your response

16876

This seems like it would be a great oh-my-zsh plugin.

over 1 year ago ·
16877

I'm not a zsh user, but feel free :)

over 1 year ago ·
16911

Or you could do this better with $PROMPT_COMMAND
https://gitorious.org/demure/dotfiles/source/subbash/prompt

over 1 year ago ·