zsh-users
 help / color / mirror / code / Atom feed
* prompt quoting question
@ 2001-08-27  4:49 Russell Hoover
  2001-08-27  7:50 ` Preben Guldberg
  2001-08-27  8:06 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: Russell Hoover @ 2001-08-27  4:49 UTC (permalink / raw)
  To: zsh-users

I have a right-prompt string:

export RPS1="%{$(print -n '\e[1;34m')%} `/usr/bin/tty | sed -e 's/\/dev\/tty//'`  \
%{$(print -n '\e[1;32m')%}%D{%A  %Y/%m/%d  %T} %{$(print -n '\e[m')%}"

which works fine, creating:

                                     r8  Monday  2001/08/27  00:29:49


where the tty (r8) is blue and the rest is green.  But this is the old style
of creating colors.  With the new, I know I need something like:

export RPS1=$'%{\e[1;34m%} tty  %{\e[1;32m%}%D{%A  %Y/%m/%d  %T} %{\e[m%}'

But when I replace "tty" in the line above with `/usr/bin/tty | sed -e 's/\/dev\/tty//'`
instead of displaying the tty number, the prompt is messed up:

                 \e[1;32mMonday  2001/08/27  00:14:45 \e[mv

and sed gives me an error message:

                 sed: 1: "s//dev/tty//": bad flag in substitute command: 't'

It seems to me the problem is in correctly quoting the 's/\/dev\/tty//' : the
single quotes (within backtics within single quotes) won't cut it.  Any clues
appreciated.

-- 
                                 // rj@panix.com //


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

* Re: prompt quoting question
  2001-08-27  4:49 prompt quoting question Russell Hoover
@ 2001-08-27  7:50 ` Preben Guldberg
  2001-08-27  8:06 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Preben Guldberg @ 2001-08-27  7:50 UTC (permalink / raw)
  To: zsh-users

Thus wrote Russell Hoover (rj@panix.com) den [010827]:

> But when I replace "tty" in the line above with `/usr/bin/tty | sed -e 's/\/dev\/tty//'`
> instead of displaying the tty number, the prompt is messed up:

>                  \e[1;32mMonday  2001/08/27  00:14:45 \e[mv

> and sed gives me an error message:

>                  sed: 1: "s//dev/tty//": bad flag in substitute command: 't'

> It seems to me the problem is in correctly quoting the 's/\/dev\/tty//' : the
> single quotes (within backtics within single quotes) won't cut it.  Any clues
> appreciated.

As for the quoting of the sed command, you could go for, say

    /usr/bin/tty | sed -e s_/dev/tty__

Peppe
-- 
                                      "Before you criticize someone, walk
Preben "Peppe" Guldberg  __/-\__       a mile in his shoes. That way, if
c928400@student.dtu.dk    (o o)        he gets angry, he'll be a mile away
----------------------oOOo (_) oOOo--  - and barefoot."    --Sarah Jackson


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

* Re: prompt quoting question
  2001-08-27  4:49 prompt quoting question Russell Hoover
  2001-08-27  7:50 ` Preben Guldberg
@ 2001-08-27  8:06 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-08-27  8:06 UTC (permalink / raw)
  To: Russell Hoover, zsh-users

On Aug 27, 12:49am, Russell Hoover wrote:
} 
} It seems to me the problem is in correctly quoting the 's/\/dev\/tty//' :
} the single quotes (within backtics within single quotes) won't cut it.

Backticks within single quotes are not recognized as quotes.  Quotation
forms normally do not nest.  There are two exceptions, and both apply
only when the outermost quotes are double quotes:

1. Inside "$(...)", all forms of quoting may appear within the parens.
2. Inside "${...}", balanced double quotes may appear within the braces.

The possible solutions are:

a. Use double quotes (or none at all) around the argument to sed.
    RPS1=$'...`/usr/bin/tty | sed -e s@/dev/tty@@`...'
b. End the $'...' expression before you begin some other quoting.
    RPS1=$'...''`/usr/bin/tty | sed -e s@/dev/tty@@`'$'...'

Neither helps in cases where the nesting quotes can't be eliminated by
other trickery; (b) might be simpler in some circumstances, but not in
this case.

For this particular question, though, I think the best solution is:

c. Use the %l or %y prompt escape instead of that sed command.

    RPS1=$'%{\e[1;34m%} %l %{\e[1;32m%}%D{%A  %Y/%m/%d  %T} %{\e[m%}'

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-08-27  8:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-27  4:49 prompt quoting question Russell Hoover
2001-08-27  7:50 ` Preben Guldberg
2001-08-27  8:06 ` Bart Schaefer

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).