zsh-users
 help / color / mirror / code / Atom feed
* Fwd: Could you provide bash's \$ which like zsh %#?
@ 2011-12-07  4:43 Geoff Wing
  2011-12-07  4:56 ` Jos Backus
  0 siblings, 1 reply; 7+ messages in thread
From: Geoff Wing @ 2011-12-07  4:43 UTC (permalink / raw)
  To: Zsh Users; +Cc: dlin.tw

Please CC replies to Daniel.

----- Forwarded message from Daniel Lin <dlin.tw@gmail.com> -----

I'm trying to move from bash to zsh.
I found a problem.  My 'expect' scripts require a '$' sign to let me know
its done.

In zsh the %# will display % when user's effective id is not 0.
But, I require another similar function which display '$' instead of '%'.

Could you consider to add this function to help bash users' life easier?

I already change my PS1="\\$"
But its function is not equal to %#.

----- End forwarded message -----


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
  2011-12-07  4:43 Fwd: Could you provide bash's \$ which like zsh %#? Geoff Wing
@ 2011-12-07  4:56 ` Jos Backus
  2011-12-07  5:03   ` Daniel Lin
  0 siblings, 1 reply; 7+ messages in thread
From: Jos Backus @ 2011-12-07  4:56 UTC (permalink / raw)
  To: Zsh Users; +Cc: dlin.tw

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

On Tue, Dec 6, 2011 at 8:43 PM, Geoff Wing <gcw@zsh.org> wrote:

> Please CC replies to Daniel.
>
> ----- Forwarded message from Daniel Lin <dlin.tw@gmail.com> -----
>
> I'm trying to move from bash to zsh.
> I found a problem.  My 'expect' scripts require a '$' sign to let me know
> its done.
>
> In zsh the %# will display % when user's effective id is not 0.
> But, I require another similar function which display '$' instead of '%'.
>
> Could you consider to add this function to help bash users' life easier?
>
> I already change my PS1="\\$"
> But its function is not equal to %#.
>
> ----- End forwarded message -----
>

How about using `%(,,)'?

Example prompt string:

%m:%~%# %(#,$,%%)

-- 
Jos Backus
jos at catnook.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
  2011-12-07  4:56 ` Jos Backus
@ 2011-12-07  5:03   ` Daniel Lin
  2011-12-07  5:09     ` Jos Backus
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lin @ 2011-12-07  5:03 UTC (permalink / raw)
  To: Jos Backus; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

Sorry, I've tried, it display strange things.
PS1='%# %(#,$,%%)'

2011/12/7 Jos Backus <jos@catnook.com>

>
>
> On Tue, Dec 6, 2011 at 8:43 PM, Geoff Wing <gcw@zsh.org> wrote:
>
>> Please CC replies to Daniel.
>>
>> ----- Forwarded message from Daniel Lin <dlin.tw@gmail.com> -----
>>
>> I'm trying to move from bash to zsh.
>> I found a problem.  My 'expect' scripts require a '$' sign to let me know
>> its done.
>>
>> In zsh the %# will display % when user's effective id is not 0.
>> But, I require another similar function which display '$' instead of '%'.
>>
>> Could you consider to add this function to help bash users' life easier?
>>
>> I already change my PS1="\\$"
>> But its function is not equal to %#.
>>
>> ----- End forwarded message -----
>>
>
> How about using `%(,,)'?
>
> Example prompt string:
>
> %m:%~%# %(#,$,%%)
>
> --
> Jos Backus
> jos at catnook.com
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
  2011-12-07  5:03   ` Daniel Lin
@ 2011-12-07  5:09     ` Jos Backus
       [not found]       ` <CAPg-njwWN=a6XDv047MwXVSYzuX3Ew5u5tprTnRqFeTpnUopcQ@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Jos Backus @ 2011-12-07  5:09 UTC (permalink / raw)
  To: Daniel Lin; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

Fwiw, here's what I am seeing (on FreeBSD -current using zsh 4.3.12):

lizzy:~% % PS1='%# %(#,$,%%) '
% %
% %
% % sudo -s
lizzy:/home/jos# PS1='%# %(#,$,%%) '
# $
# $

On Tue, Dec 6, 2011 at 9:03 PM, Daniel Lin <dlin.tw@gmail.com> wrote:

> PS1='%# %(#,$,%%)'



-- 
Jos Backus
jos at catnook.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
       [not found]         ` <CAETOPp3+tdbAMmf9T49Hqc1gfZvYqzXgiLRiAZ=aSCkwWsHKKw@mail.gmail.com>
@ 2011-12-07  7:04           ` Daniel Lin
  2011-12-07  8:16             ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Lin @ 2011-12-07  7:04 UTC (permalink / raw)
  To: Jos Backus; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1449 bytes --]

I got the description on 'man zshmisc'

       %#     A  `#'  if  the  shell is running with privileges, a `%' if
not.
              Equivalent to `%(!.#.%%)'.  The definition of `privileged',
 for
              these  purposes,  is  that either the effective user ID is
zero,
              or, if POSIX.1e capabilities are supported, that  at  least
 one
              capability  is  raised  in  either  the Effective or
Inheritable
              capability vectors.

So, to match the document, I should change the prompt to
PS1='%(!.#.$)'

2011/12/7 Jos Backus <jos@catnook.com>

> What do you mean by 'document'?
>
> Jos
> On Dec 6, 2011 9:35 PM, "Daniel Lin" <dlin.tw@gmail.com> wrote:
>
>> I think it may workable by following setting.
>> But, I don't know how to get its document.
>>
>> zsh --version                                                   ~
>> 13:29:54 (1)
>> zsh 4.3.12 (i686-pc-linux-gnu)
>>
>> PS1='%(#,#,$)'  # simulate bash's \$
>> in normal user, it will display $
>> in super user, it will display #
>>
>> 2011/12/7 Jos Backus <jos@catnook.com>
>>
>>> Fwiw, here's what I am seeing (on FreeBSD -current using zsh 4.3.12):
>>>
>>> lizzy:~% % PS1='%# %(#,$,%%) '
>>> % %
>>> % %
>>> % % sudo -s
>>> lizzy:/home/jos# PS1='%# %(#,$,%%) '
>>> # $
>>> # $
>>>
>>> On Tue, Dec 6, 2011 at 9:03 PM, Daniel Lin <dlin.tw@gmail.com> wrote:
>>>
>>>> PS1='%# %(#,$,%%)'
>>>
>>>
>>>
>>> --
>>> Jos Backus
>>> jos at catnook.com
>>>
>>
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
  2011-12-07  7:04           ` Daniel Lin
@ 2011-12-07  8:16             ` Bart Schaefer
  2011-12-07 10:10               ` Daniel Lin
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2011-12-07  8:16 UTC (permalink / raw)
  To: Daniel Lin; +Cc: Zsh Users

On Dec 7,  1:03pm, Daniel Lin wrote:
} Subject: Re: Could you provide bash's \$ which like zsh %#?
} 
} Sorry, I've tried, it display strange things.
} PS1='%# %(#,$,%%)'

That was Josh's attempt to give you one example that shows both %#
and a conditional string that displays something not quite the same,
so that you could compare the two.  It was not intended to be the
prompt that you would use, just a sample of what could be done.

On Dec 7,  3:04pm, Daniel Lin wrote:
} Subject: Re: Could you provide bash's \$ which like zsh %#?
}
} So, to match the document, I should change the prompt to
} PS1='%(!.#.$)'

Yes, almost.  You probably want the trailing space in there.

PS1='%(!.#.$) '

Equivalently, %(#,#,$) says "if the UID is zero, pound, else dollar"
"Running with privileges" could mean something other than "running as
the root user" in obscure circumstances.  %(#,,) is the generalized
form of %(!,,), so that you can test for explicit UID; the default
when no UID is given is zero.  So another possible example is

PS1='%(2#,Running as daemon ,)%(!.#.$) '

[Assuming that UID 2 is "daemon" as it is on my Linux box.]


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Could you provide bash's \$ which like zsh %#?
  2011-12-07  8:16             ` Bart Schaefer
@ 2011-12-07 10:10               ` Daniel Lin
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Lin @ 2011-12-07 10:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

Thanks, learn a lot.

2011/12/7 Bart Schaefer <schaefer@brasslantern.com>

> On Dec 7,  1:03pm, Daniel Lin wrote:
> } Subject: Re: Could you provide bash's \$ which like zsh %#?
> }
> } Sorry, I've tried, it display strange things.
> } PS1='%# %(#,$,%%)'
>
> That was Josh's attempt to give you one example that shows both %#
> and a conditional string that displays something not quite the same,
> so that you could compare the two.  It was not intended to be the
> prompt that you would use, just a sample of what could be done.
>
> On Dec 7,  3:04pm, Daniel Lin wrote:
> } Subject: Re: Could you provide bash's \$ which like zsh %#?
> }
> } So, to match the document, I should change the prompt to
> } PS1='%(!.#.$)'
>
> Yes, almost.  You probably want the trailing space in there.
>
> PS1='%(!.#.$) '
>
> Equivalently, %(#,#,$) says "if the UID is zero, pound, else dollar"
> "Running with privileges" could mean something other than "running as
> the root user" in obscure circumstances.  %(#,,) is the generalized
> form of %(!,,), so that you can test for explicit UID; the default
> when no UID is given is zero.  So another possible example is
>
> PS1='%(2#,Running as daemon ,)%(!.#.$) '
>
> [Assuming that UID 2 is "daemon" as it is on my Linux box.]
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-12-07 10:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-07  4:43 Fwd: Could you provide bash's \$ which like zsh %#? Geoff Wing
2011-12-07  4:56 ` Jos Backus
2011-12-07  5:03   ` Daniel Lin
2011-12-07  5:09     ` Jos Backus
     [not found]       ` <CAPg-njwWN=a6XDv047MwXVSYzuX3Ew5u5tprTnRqFeTpnUopcQ@mail.gmail.com>
     [not found]         ` <CAETOPp3+tdbAMmf9T49Hqc1gfZvYqzXgiLRiAZ=aSCkwWsHKKw@mail.gmail.com>
2011-12-07  7:04           ` Daniel Lin
2011-12-07  8:16             ` Bart Schaefer
2011-12-07 10:10               ` Daniel Lin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).