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.
Written by Vasili Sviridov
Related protips
3 Responses
This seems like it would be a great oh-my-zsh plugin.
over 1 year ago
·
I'm not a zsh user, but feel free :)
over 1 year ago
·
Or you could do this better with $PROMPT_COMMAND
https://gitorious.org/demure/dotfiles/source/subbash/prompt
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Sudo
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#