Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!


Click here to return to the 'Not needed if you are already defining PS1 (+ example)' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Not needed if you are already defining PS1 (+ example)
Authored by: ClassicUser on Wed, Mar 19 2008 at 6:10PM PDT
To clarify: If you are already defining a custom PS1 entry in such an rc file, it will be picked up by "sudo -s", as well - so this specific "SUDO_PS1" entry would not be needed.

FYI, I use a custom entry within my .profile to display the path within brackets - truncating to just the final directory, if the path grows too long (see "MAXPWDLEN"):

# set prompt (add brackets to standard prompt)
## default: PS1="\h:\w \u\$ "
## previous: export PS1="[\h:\w] \u\\$ "
MAXPWDLEN=21
export PS1='[\h:\
$( MYPWD=${PWD/#$HOME/~} && [ ${#MYPWD} -gt $MAXPWDLEN ] && \
printf "%s" "…${MYPWD/${MYPWD%*/*}/}" || \
printf "%s" "${MYPWD}")] \
\u\$ '

This results in, for example:

[mymac:/Users/classic] classic$

…as well as responding to input as:
[mymac:/Users/classic] classic$ sudo -s
[mymac:/Users/classic] root# cd ~/Library/Application\ Support/
[mymac:…/Application Support] root# cd /System/Library/Frameworks/Message.framework/Versions/B/Resources/English.lproj/
[mymac:…/English.lproj] root# exit
[mymac:/Users/classic] classic$

(remember, ellipses are entered via "Option-semicolon"; if these don't work for you, just substitute 3 periods, or the like)

[ Reply to This | # ]

Not needed if you are already defining PS1 (+ example)
Authored by: joshewah on Fri, Mar 21 2008 at 9:06AM PDT
I use the following prompt in .profile and using sudo -s does not keep it:
export PS1="\[\033[01;37m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] "

I bet you could run visudo and change something in the sudo config file to fix this globally.

[ Reply to This | # ]
Not needed if you are already defining PS1 (+ example)
Authored by: ClassicUser on Sat, Apr 19 2008 at 11:44AM PDT
Ah, but .profile is only run for direct login shells - of which performing a sudo -s doesn't qualify, as it is merely starts a sub-shell within that same session.

If you put that same command in your .bashrc file instead, you should be better off. Also, note that several folks simply source the one file from the other - I have a grand total of one line in my .profile:

source $HOME/.bashrc

…to handle just such a provision, and ensure the same environment is established upon first login, as well as when starting sub-shells.

[ Reply to This | # ]

Not needed if you are already defining PS1 (+ example)
Authored by: maxlyth on Thu, May 1 2008 at 7:48PM PDT
Yoy are missing a backslash in the first printf line. It should read:
printf "%s" "…${MYPWD/${MYPWD%*\/*}/}" || \

[ Reply to This | # ]