Re: [gentoo-user] Bash prompt colours

2021-12-07 Thread Frank Steinmetzger
Am Tue, Dec 07, 2021 at 10:26:11AM -0700 schrieb Grant Taylor:
> Some drive-by after-the-fact comments:
> 
> On 12/6/21 4:03 PM, Frank Steinmetzger wrote:
> >  [ "$MC_SID" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}MC "
> >  [ "$RANGER_LEVEL" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}R "
> 
> I've taken to using things like the following:
> 
>PS1_JOBS_COUNT="${PS1_JOBS_COUNT}${MC_SID:+MC }${RANGER_LEVEL:+R }"
> 
> Leverage Bash's (and Zsh's) expansion conditional.  If the variable is set,
> then expand it to a different value.

By jove, you’re right. Maybe I’ve written that stuff before I knew about
default values. I checked in that code in September of 2016. And it could
possibly be even much older, because I clean up my config git repository
only very sporadically, as in two or three times a year.

>${VARIABLE:+alternate text to show if VARIABLE is set}
> 
> > if [[ -z "$PROMPT_COMMAND" ]]; then
> > PROMPT_COMMAND=__jobsprompt
> > else
> > PROMPT_COMMAND="$PROMPT_COMMAND ; __jobsprompt"
> > fi
> 
> Is there a reason to not simply do the following, eliminating the if
> conditional:
> 
>PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND} ; __jobsprompt}

Maybe inexperience? :D
Or sometimes, explicit is better than implicit?

-- 
Grüße | Greetings | Qapla’
Please do not share anything from, with or about me on any social network.

I had a problem and used Java. Now I have a ProblemFactory.


signature.asc
Description: PGP signature


Re: [gentoo-user] Bash prompt colours

2021-12-07 Thread Grant Taylor

Some drive-by after-the-fact comments:

On 12/6/21 4:03 PM, Frank Steinmetzger wrote:

 [ "$MC_SID" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}MC "
 [ "$RANGER_LEVEL" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}R "


I've taken to using things like the following:

   PS1_JOBS_COUNT="${PS1_JOBS_COUNT}${MC_SID:+MC }${RANGER_LEVEL:+R }"

Leverage Bash's (and Zsh's) expansion conditional.  If the variable is 
set, then expand it to a different value.


   ${VARIABLE:+alternate text to show if VARIABLE is set}


if [[ -z "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND=__jobsprompt
else
PROMPT_COMMAND="$PROMPT_COMMAND ; __jobsprompt"
fi


Is there a reason to not simply do the following, eliminating the if 
conditional:


   PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND} ; __jobsprompt}



--
Grant. . . .
unix || die



Re: [gentoo-user] Bash prompt colours

2021-12-06 Thread Frank Steinmetzger
Am Fri, Dec 03, 2021 at 02:43:54PM + schrieb Peter Humphrey:

> > > > Hello list,
> > > > 
> > > > Is there a way to set the colour of a bash prompt according to
> > > > whether the user has SSH'd in?
> > > > […]
> > > When you are connected via SSH, the environment variable
> > > SSH_CONNECTION is set. I store the color in a variable and set it to
> > > yellow if `[[ -n "${SSH_CONNECTION}" ]]`. I can't give you the exact
> > > snippet since I use Zsh, but it should be possible to use a variable
> > > as color in bash's prompt?
> > > 
> > > Kind regards, tastytea
> > 
> > This link expands upon tastytea's idea:
> > 
> > https://unix.stackexchange.com/questions/217270/change-ps1-color-when-> 
> > connected-to-other-host-via-ssh
> 
> Thank you both. Now I just have to shoehorn it into /etc/bash/bashrc on the 
> SSH server...

I expanded on that idea somewhat further. When I am in midnight commander
and press Ctrl+O to open a fullscreen shell, I sometimes forget after a
while that it was an mc shell, and so blindly quit it with ctrl+D, which
also kills the mc process. So a long time ago I expanded my PS1 in ~/.bashrc
for those shells to show the number of backgrounded processes and “subshell
type” like so:


__jobsprompt() {
PS1_JOBS_COUNT=`jobs -p | wc -l`
if [ $PS1_JOBS_COUNT -eq 0 ]; then
PS1_JOBS_COUNT=
else
PS1_JOBS_COUNT="$PS1_JOBS_COUNT "
fi
[ "$MC_SID" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}MC "
[ "$RANGER_LEVEL" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}R "
}

if [[ -z "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND=__jobsprompt
else
PROMPT_COMMAND="$PROMPT_COMMAND ; __jobsprompt"
fi

PS1="$CBPURPLE\u$CDGRAY@$CBGREEN\h$CRESET $CBBLUE\w 
$CRED"'$PS1_JOBS_COUNT'$CRESET"


Those $C… strings of course being shell codes for colours (CB…=bold). Note
the single quotes within the string. PS1 shall contain the actual string
'$PS1_JOBS_COUNT', so that the variable is expanded anew in every prompt.

-- 
Grüße | Greetings | Qapla’
Please do not share anything from, with or about me on any social network.

I just took an IQ test. The results were negative.


signature.asc
Description: PGP signature


Re: [gentoo-user] Bash prompt colours

2021-12-03 Thread Peter Humphrey
On Friday, 3 December 2021 13:30:29 GMT Michael wrote:
> On Friday, 3 December 2021 12:08:05 GMT tastytea wrote:
> > On 2021-12-03 11:17+ Peter Humphrey  
wrote:
> > > Hello list,
> > > 
> > > Is there a way to set the colour of a bash prompt according to
> > > whether the user has SSH'd in?
> > > 
> > > This machine is a compile host for some others on the LAN, and it
> > > would be helpful if it were more obvious that I'm connected to
> > > another machine. Of course, the standard prompt tells me the machine
> > > name, but something more conspicuous would help.
> > 
> > When you are connected via SSH, the environment variable 
SSH_CONNECTION
> > is set. I store the color in a variable and set it to yellow if
> > `[[ -n "${SSH_CONNECTION}" ]]`. I can't give you the exact snippet
> > since I use Zsh, but it should be possible to use a variable as color
> > in bash's prompt?
> > 
> > Kind regards, tastytea
> 
> This link expands upon tastytea's idea:
> 
> https://unix.stackexchange.com/questions/217270/change-ps1-color-when-> 
> connected-to-other-host-via-ssh

Thank you both. Now I just have to shoehorn it into /etc/bash/bashrc on the 
SSH server...

-- 
Regards,
Peter.






Re: [gentoo-user] Bash prompt colours

2021-12-03 Thread Michael
On Friday, 3 December 2021 12:08:05 GMT tastytea wrote:
> On 2021-12-03 11:17+ Peter Humphrey  wrote:
> > Hello list,
> > 
> > Is there a way to set the colour of a bash prompt according to
> > whether the user has SSH'd in?
> > 
> > This machine is a compile host for some others on the LAN, and it
> > would be helpful if it were more obvious that I'm connected to
> > another machine. Of course, the standard prompt tells me the machine
> > name, but something more conspicuous would help.
> 
> When you are connected via SSH, the environment variable SSH_CONNECTION
> is set. I store the color in a variable and set it to yellow if
> `[[ -n "${SSH_CONNECTION}" ]]`. I can't give you the exact snippet
> since I use Zsh, but it should be possible to use a variable as color
> in bash's prompt?
> 
> Kind regards, tastytea

This link expands upon tastytea's idea:

https://unix.stackexchange.com/questions/217270/change-ps1-color-when-connected-to-other-host-via-ssh


signature.asc
Description: This is a digitally signed message part.


Re: [gentoo-user] Bash prompt colours

2021-12-03 Thread tastytea
On 2021-12-03 11:17+ Peter Humphrey  wrote:

> Hello list,
> 
> Is there a way to set the colour of a bash prompt according to
> whether the user has SSH'd in?
> 
> This machine is a compile host for some others on the LAN, and it
> would be helpful if it were more obvious that I'm connected to
> another machine. Of course, the standard prompt tells me the machine
> name, but something more conspicuous would help.

When you are connected via SSH, the environment variable SSH_CONNECTION
is set. I store the color in a variable and set it to yellow if 
`[[ -n "${SSH_CONNECTION}" ]]`. I can't give you the exact snippet
since I use Zsh, but it should be possible to use a variable as color
in bash's prompt?

Kind regards, tastytea

-- 
Get my PGP key with `gpg --locate-keys tasty...@tastytea.de` or at
.


pgpPmG8W_1HhU.pgp
Description: Digitale Signatur von OpenPGP


[gentoo-user] Bash prompt colours

2021-12-03 Thread Peter Humphrey
Hello list,

Is there a way to set the colour of a bash prompt according to whether the 
user has SSH'd in?

This machine is a compile host for some others on the LAN, and it would be 
helpful if it were more obvious that I'm connected to another machine. Of 
course, the standard prompt tells me the machine name, but something more 
conspicuous would help.

-- 
Regards,
Peter.






[gentoo-user] Bash prompt

2005-09-14 Thread Charles Trois

Hello!

I am getting confused with profile, bashrc, etc.
The prompt string I want to use is

PS1=[EMAIL PROTECTED] \W]\$ 

I therefore wrote it in /etc/profile (at two levels, root and non-root), 
~/.bash_profile and ~/.bashrc.


If I log in as a plain user (moi), I get this:

[EMAIL PROTECTED] moi]$

which is all right. But, if I log in as root, I get the basic default

bash-2.05b# .

I thought that /etc/profile should provide the default, but I was 
obviously wrong. Trying to mend things, I created two files 
/root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now, 
logging in as root, the result is


[EMAIL PROTECTED] root]$

which is wrong, since $ appears in place of #, as though my syntax 
of PS1 were incorrect, but I don't see that it is.


How am I to clean up all this? I'll be grateful for all suggestions.

Charles



--
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Hans-Werner Hilse
Hi,

On Wed, 14 Sep 2005 11:15:13 +0200
Charles Trois [EMAIL PROTECTED] wrote:

 I am getting confused with profile, bashrc, etc.
 The prompt string I want to use is
 
 PS1=[EMAIL PROTECTED] \W]\$ 
 
 [...]
 I thought that /etc/profile should provide the default, but I was 
 obviously wrong. Trying to mend things, I created two files 
 /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now, 
 logging in as root, the result is
 
 [EMAIL PROTECTED] root]$
 
 which is wrong, since $ appears in place of #, as though my syntax 
 of PS1 were incorrect, but I don't see that it is.

That's probably due to multi level backslash escaping. Because you
surrounded the prompt string with , the backslash isn't surviving the
first parser run by bash. You'd need to double it or even triple it
(because the $ may need escaping on the first level, too).

-hwh
-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Holly Bostick
Charles Trois schreef:
 Hello!
 
 I am getting confused with profile, bashrc, etc. The prompt string I 
 want to use is
 
 PS1=[EMAIL PROTECTED] \W]\$ 
 
 I therefore wrote it in /etc/profile (at two levels, root and 
 non-root), ~/.bash_profile and ~/.bashrc.
 
 If I log in as a plain user (moi), I get this:
 
 [EMAIL PROTECTED] moi]$
 
 which is all right. But, if I log in as root, I get the basic default
 
 
 
 
 
 bash-2.05b# .
 
 I thought that /etc/profile should provide the default, but I was 
 obviously wrong. Trying to mend things, I created two files 
 /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now,
  logging in as root, the result is
 
 [EMAIL PROTECTED] root]$
 
 which is wrong, since $ appears in place of #, as though my 
 syntax of PS1 were incorrect, but I don't see that it is.

No, it's not incorrect, but if you wrote the exact same PS1 in the root
entry as in the user entry, perhaps you see that there's a 'literal'
dollar sign character at the end:

PS1=[EMAIL PROTECTED] \W]\$ 

which is going to be printed as itself, as you are not using any code to
change it to the 'correct' character based on user (perhaps bash thinks
you've escaped the closing bracket, not the following $. A space
between the bracket and the \$ might solve this, but I've never really
got /$ to work properly. It may, however, be because of the 'login shell
issue' -- see below, but basically, if you're using su and not su -, your
UID is not changing, so the /$ is not changing either).

Now, as to /etc/profile, /.bash_profile, and /.bashrc;

OK, this is a bit complex. /etc/profile should in fact provide the
default if no other is provided (bash_profile overrides, but since if a
bash_profile is provided, as it seems to be on Gentoo, it only contains
a little scriptlet that says look at (source) ~/.bashrc, making
~/.bashrc the
*real* override. This is how it works on my system, and this seems to be
a generally default behaviour, as I've seen it under all distros where I
tried to customize the bash prompt, as I usually do if I stick with the
distro for any length of time).

My gentoo /etc/profile says:

if [ -n ${BASH_VERSION} ] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color.  We leave out color here because not all
# terminals support it.
if [ -f /etc/bash/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we
source it
# from here.  It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without
putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='[EMAIL PROTECTED] \w \$ '
fi
else
# Setup a bland default prompt.  Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1=[EMAIL PROTECTED] -n | cut -f1 -d.` \$ 
fi

So, if there's a /etc/bash/bashrc found, it is sourced under all
circumstances, but if for some reason that doesn't work (like why??) the
prompt is set at

[EMAIL PROTECTED] workdir appropriate_symbol_for_user_class

Fine.

If there is no /etc/bash/bashrc found (as in the case of using another
shell), I think that the prompt is set to be the same thing, but just
with different language, since as mentioned, every shell doesn't
understand bash sequences.

OK. So far so good.

So this tells us that the first thing you did 'incorrectly' was changing
/etc/profile, instead of /etc/bash/bashrc (or /etc/bashrc, if that's
where bash 2 puts it).

This fits with what I know, insofar as I know that bashrc (preferably in
~/) trumps everything, generally. So it makes sense to me that if you
don't have a .bashrc in your home, there's a default one in /etc that
basically trumps everything.

So let's look at /etc/bash/bashrc (I'm using bash 3.0). The relevant
entries would seem to be:

if ${use_color} ; then
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
else
PS1='\[\033[01;[EMAIL PROTECTED] \[\033[01;34m\]\w \$ 
\[\033[00m\]'
fi
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='[EMAIL PROTECTED] \W \$ '
else
PS1='[EMAIL PROTECTED] \w \$ '
fi
fi

Fine, so if the user is root, and it's a color term, the prompt is

hostname short_path_to_workdir symbol (in this case presumably '#')

with colors, and if the user is not root, it's

[EMAIL PROTECTED] full_path_to_workdir symbol (in this case, presumably '$')
with colors.

If there's no color, for 

Re: [gentoo-user] Bash prompt

2005-09-14 Thread wiqd
On Wed, 2005-09-14 at 11:15 +0200, Charles Trois wrote:
 Hello!
 
Hi Charles,

 I am getting confused with profile, bashrc, etc.
 The prompt string I want to use is
 
 PS1=[EMAIL PROTECTED] \W]\$ 
 
 I therefore wrote it in /etc/profile (at two levels, root and non-root), 
 ~/.bash_profile and ~/.bashrc.
 
 If I log in as a plain user (moi), I get this:
 
 [EMAIL PROTECTED] moi]$
 
 which is all right. But, if I log in as root, I get the basic default
 
 bash-2.05b# .
 
 I thought that /etc/profile should provide the default, but I was 
 obviously wrong. Trying to mend things, I created two files 
 /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now, 
 logging in as root, the result is
 
 [EMAIL PROTECTED] root]$
 
 which is wrong, since $ appears in place of #, as though my syntax 
 of PS1 were incorrect, but I don't see that it is.
 
 How am I to clean up all this? I'll be grateful for all suggestions.
 

Put this into /home/user/.profile

PS1=[EMAIL PROTECTED] \W]$ 

and this into /root/.profile

PS1=[EMAIL PROTECTED] \W]# 

And all should be fine.

 Charles
 
 
 
Greg

-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Willie Wong
On Wed, Sep 14, 2005 at 01:25:00PM +0200, Holly Bostick wrote:
 Charles Trois schreef:
  Hello!
  
  I am getting confused with profile, bashrc, etc. The prompt string I 
  want to use is
  
  PS1=[EMAIL PROTECTED] \W]\$ 
  
  I therefore wrote it in /etc/profile (at two levels, root and 
  non-root), ~/.bash_profile and ~/.bashrc.
  
  If I log in as a plain user (moi), I get this:
  
  [EMAIL PROTECTED] moi]$
  
  which is all right. But, if I log in as root, I get the basic default
  
  
  
  
  
  bash-2.05b# .
  
  I thought that /etc/profile should provide the default, but I was 
  obviously wrong. Trying to mend things, I created two files 
  /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now,
   logging in as root, the result is
  
  [EMAIL PROTECTED] root]$
  
  which is wrong, since $ appears in place of #, as though my 
  syntax of PS1 were incorrect, but I don't see that it is.
 
 No, it's not incorrect, but if you wrote the exact same PS1 in the root
 entry as in the user entry, perhaps you see that there's a 'literal'
 dollar sign character at the end:
 
 PS1=[EMAIL PROTECTED] \W]\$ 
 
 which is going to be printed as itself, as you are not using any code to
 change it to the 'correct' character based on user (perhaps bash thinks
 you've escaped the closing bracket, not the following $. A space
 between the bracket and the \$ might solve this, but I've never really
 got /$ to work properly. It may, however, be because of the 'login shell
 issue' -- see below, but basically, if you're using su and not su -, your
 UID is not changing, so the /$ is not changing either).

No. That's wrong. 

[08:13 AM]wwong ~ $ id
uid=1001(wwong) gid=0(root) 
groups=0(root),6(disk),10(wheel),11(floppy),16(cron),18(audio),19(cdrom),27(video),35(games),245(locate),250(portage),408(web),440(speech),443(slocate)
[08:13 AM]wwong ~ $ su
Password: 
sep wwong # id
uid=0(root) gid=0(root) 
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
sep wwong # 


snip

 So ~/.bashrc is king of the hill, as it is apparently meant to be, so
 we'll talk about that. As I said, the default ~/.bashrc contained a
 number of aliases, and because I use a lot of aliases, I worked with
 ~/.bashrc a lot (for both home and root). Using a lot of links (posted
 below) I was able to get a nice 3-line prompt that I like. I then copied
 the prompt to root's bashrc and made minor changes (the colors, mostly).
 and that was fine.
 
 Then I tackled the problem of the login shell.
 
 You see, ~/.bashrc is only sourced when you login (to the terminal,
 which, don't forget, is a virtual console). So if you're in the term as
 a user, and then you su normally to root, root's bashrc is not going to
 be sourced, and (among other issues) you're not going to get the right
 prompt (seemingly because your UID doesn't actively change to UID 0, but
 rather you remain the regular user with elevated permissions).

1. Your UID does change. See the experiment above. 
2. .bashrc is sourced for ALL interactive shells. .bash_profile is
sourced ONLY for login shells. So: opening an xterm sources .bashrc.
Logging in remotely via ssh sources .bash_profile. 
3. su opens an interactive shell. It DOES source .bashrc

 The solution to this is (for me, as I really like bash but am not all
 that good with it as yet, so any more 'elegant' solutions are unknown to
 me), is to make sure my su is always a login prompt (alias su=su -),
 so that root's bashrc is sourced when I su, so I can use root's aliases,

4. su - would open a login shell, and thus source .bash_profile
instead of .bashrc

 and get root's $PATH, since there's nothing more annoying to me than
 su-ing to root and still getting a 'file not found' error because
 whatever I'm trying to do is still not in my $PATH, because root's PATH
 was somehow not exported by su-ing. I also added an ENV_SUPATH variable

I would say something is borked on your setup. Be default, su would
look in /etc/login.def for ENV_SUPATH and ENV_PATH for default PATHs
for superusers and users respectively. Here there's also a difference
between su and su -. su loads ENV_SUPATH from /etc/login.def,
which by default is /sbin;/bin;/usr/sbin;/usr/bin. For su -. because
it invokes a login shell, it should grab the path from /etc/profile,
which in turn grabs it from /etc/profile.env, which is created by
env-update from the information in /etc/env.d

-- 
I've got a patent pending on swallowing, oxidation, and chewing gum.
Sortir en Pantoufles: up 33 days, 15:15
-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Willie Wong
On Wed, Sep 14, 2005 at 11:30:19AM +0200, Hans-Werner Hilse wrote:
 Hi,
 
 On Wed, 14 Sep 2005 11:15:13 +0200
 Charles Trois [EMAIL PROTECTED] wrote:
 
  I am getting confused with profile, bashrc, etc.
  The prompt string I want to use is
  
  PS1=[EMAIL PROTECTED] \W]\$ 
  
  [...]
  I thought that /etc/profile should provide the default, but I was 
  obviously wrong. Trying to mend things, I created two files 
  /root/.bash_profile and /root/.bashrc, writing just PS1 in each. Now, 
  logging in as root, the result is
  
  [EMAIL PROTECTED] root]$
  
  which is wrong, since $ appears in place of #, as though my syntax 
  of PS1 were incorrect, but I don't see that it is.
 
 That's probably due to multi level backslash escaping. Because you
 surrounded the prompt string with , the backslash isn't surviving the
 first parser run by bash. You'd need to double it or even triple it
 (because the $ may need escaping on the first level, too).

Use single quotes if you want to use \$
$ is a reserved character in bash. So when using double quotes, you
need to type \\$

sep wwong # export PS1=[test]\$ 
[test]$ export PS1=[test]\\$ 
[test]# export PS1='[test]\\$ '
[test]$ export PS1='[test]\$ '
[test]# 

W
-- 
Dude, this is making the same approximation twice in a row. It's like a 
whack-a-mole game.
~DeathMech, Some Student. P-town PHY 205
Sortir en Pantoufles: up 33 days, 15:41
-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Holly Bostick
Willie Wong schreef:
 On Wed, Sep 14, 2005 at 01:25:00PM +0200, Holly Bostick wrote:
 
 Charles Trois schreef:
 
 I thought that /etc/profile should provide the default, but I was
  obviously wrong. Trying to mend things, I created two files 
 /root/.bash_profile and /root/.bashrc, writing just PS1 in each. 
 Now, logging in as root, the result is
 
 [EMAIL PROTECTED] root]$
 
 which is wrong, since $ appears in place of #, as though my 
 syntax of PS1 were incorrect, but I don't see that it is.
 
 No, it's not incorrect, but if you wrote the exact same PS1 in the 
 root entry as in the user entry, perhaps you see that there's a 
 'literal' dollar sign character at the end:
 
 PS1=[EMAIL PROTECTED] \W]\$ 
 
 which is going to be printed as itself, as you are not using any 
 code to change it to the 'correct' character based on user (perhaps
  bash thinks you've escaped the closing bracket, not the following 
 $. A space between the bracket and the \$ might solve this, but
 I've never really got /$ to work properly. It may, however, be 
 because of the 'login shell issue' -- see below, but basically, if 
 you're using su and not su -, your UID is not changing, so the /$ 
 is not changing either).
 
 
 No. That's wrong.
 
 [08:13 AM]wwong ~ $ id uid=1001(wwong) gid=0(root) 
 groups=0(root),6(disk),10(wheel),11(floppy),16(cron),18(audio),19(cdrom),27(video),35(games),245(locate),250(portage),408(web),440(speech),443(slocate)
  [08:13 AM]wwong ~ $ su Password: sep wwong # id uid=0(root) 
 gid=0(root) 
 groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
  sep wwong #
 
snip of Willie wiping the floor with me :) 
 and get root's $PATH, since there's nothing more annoying to me 
 than su-ing to root and still getting a 'file not found' error 
 because whatever I'm trying to do is still not in my $PATH, because
  root's PATH was somehow not exported by su-ing. I also added an 
 ENV_SUPATH variable
 
 
 I would say something is borked on your setup. Be default, su would 
 look in /etc/login.def for ENV_SUPATH and ENV_PATH for default PATHs
  for superusers and users respectively. Here there's also a
 difference between su and su -. su loads ENV_SUPATH from
 /etc/login.def, which by default is /sbin;/bin;/usr/sbin;/usr/bin.
 For su -. because it invokes a login shell, it should grab the path
 from /etc/profile, which in turn grabs it from /etc/profile.env,
 which is created by env-update from the information in /etc/env.d

OK, you're right. I think that the problems that I was working around
may have been based in *sudo*, not su itself, which works fine (now), as
does sudo su. But when I was setting up my system with sudo (like a
month and a half ago), I had all kinds of issues, because sudo did not
seem to source anything (or at least not in the way I expected). For
example, I had some weird borked PATH (the default ENV_SUPATH as you
said above, rather than the root PATH, which I would expect from a sudo
su -) , programs opened as (sudo su) root were opening with user
colors and themes (though they worked with root privs), and that sort of
thing. It was really bizarre, so I had a bunch of bizarre workarounds to
get things to work as it seemed they should, but didn't.

Maybe I borked something back in the day. It's also possible that I was
having real issues, and an upgrade to shadow (hey!! *that's* the program
where version 4.0.9 obsoletes ENV_SUPATH!) and/or sudo solved the issues
and I just didn't notice (I did remember that I knew I was unlikely to
notice the update that was going to obsolete ENV_SUPATH, and in fact, I
wouldn't really note an update to shadow without making a note to myself
to watch out for it. Which I should probably do).

In any case, I completely forgot that sudo was involved at all, so...
sorry, and just ignore me :) . I'll be busy cleaning up my bashrcs.
anyway (now that everything looks to be working properly :) ).

Holly

-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] Bash prompt

2005-09-14 Thread Willie Wong
On Wed, Sep 14, 2005 at 05:45:08PM +0200, Holly Bostick wrote:
 OK, you're right. I think that the problems that I was working around
 may have been based in *sudo*, not su itself, which works fine (now), as
 does sudo su. But when I was setting up my system with sudo (like a
 month and a half ago), I had all kinds of issues, because sudo did not
 seem to source anything (or at least not in the way I expected). For
 example, I had some weird borked PATH (the default ENV_SUPATH as you
 said above, rather than the root PATH, which I would expect from a sudo
 su -) , programs opened as (sudo su) root were opening with user
 colors and themes (though they worked with root privs), and that sort of
 thing. It was really bizarre, so I had a bunch of bizarre workarounds to
 get things to work as it seemed they should, but didn't.

right. sudo doesn't start a sub-shell. It executes commands with
escalated privileges. On the other hand, you *can* start sudo with 

sudo -i 

which, at least according to the manpage, would start a login shell
and set all the env variables. What I am not sure is whether sudo -i
asks you for the root password or the sudo password 

W
-- 
Tried to play my shoehorn... all I got was footnotes!
Sortir en Pantoufles: up 33 days, 19:10
-- 
gentoo-user@gentoo.org mailing list