zsh-workers
 help / color / mirror / code / Atom feed
* History expansion modifiers :t, :h, :r and :e break quoting in some cases
@ 2013-07-02 17:43 Axel Beckert
  2013-07-03  8:57 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Beckert @ 2013-07-02 17:43 UTC (permalink / raw)
  To: zsh-workers

Hi,

Today I was slightly confused about the "`quote>" prompt after the
following commands:

% echo 'foo/bar'
foo/bar
% echo !$:h
`quote> ^C
echo 'foo
% 

(I manually added the "^C" above where I pressed Ctrl-C. My real-life
case was more complex and had blanks in the file names and hence
qualifies the quoting. :-)

So ":h" seems not only to strip "/bar" as I would have expected but
also strips the trailing single quote.

The same happens with ":e" as well as with ":t" or ":r" and the
leading single quote:

% echo 'foo/bar.bla'
foo/bar.bla
 echo !$:e
`quote> ^C
echo bla'
%

% echo 'foo/bar'
foo/bar
% echo !$:t
`quote> ^C
echo bar'
%

% echo 'foo/bar.bla'
foo/bar.bla
% echo !$:r
`quote> ^C
echo 'foo/bar
%

It also behaves the same way with double quotes instead of single
quotes.

At least for enclosing double and single quotes, I would have expected
that these are not stripped on :t or :h. I can imagine that it may be
harder to implement for more complex quoting variants like

% echo "foo '"'/"'"' bla"
foo '/"' bla
% 

Initially noticed with zsh 4.3.17 in Debian Wheezy, but also
reproducible with zsh 5.0.2 in Debian Unstable.

		Kind regards, Axel
-- 
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | abe@deuxchevaux.org  (Mail)
 X   See http://www.asciiribbon.org/              | abe@noone.org (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)


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

* Re: History expansion modifiers :t, :h, :r and :e break quoting in some cases
  2013-07-02 17:43 History expansion modifiers :t, :h, :r and :e break quoting in some cases Axel Beckert
@ 2013-07-03  8:57 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2013-07-03  8:57 UTC (permalink / raw)
  To: zsh-workers

On Tue, 02 Jul 2013 19:43:56 +0200
Axel Beckert <abe@deuxchevaux.org> wrote:
> Today I was slightly confused about the "`quote>" prompt after the
> following commands:
> 
> % echo 'foo/bar'
> foo/bar
> % echo !$:h
> `quote> ^C
> echo 'foo
> % 
> 
> (I manually added the "^C" above where I pressed Ctrl-C. My real-life
> case was more complex and had blanks in the file names and hence
> qualifies the quoting. :-)
> 
> So ":h" seems not only to strip "/bar" as I would have expected but
> also strips the trailing single quote.

Yes, the history modifiers know essentially nothing about shell syntax.
They are applied very early in processing, before any lexical analysis.

The only workaround I can see that would process the command line more
intelligently would be some function running in the line editor, which
has access to more intelligence, including some existing functions for
analysing command lines.  However, that's not a 5-minute job.

pws


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

end of thread, other threads:[~2013-07-03  9:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-02 17:43 History expansion modifiers :t, :h, :r and :e break quoting in some cases Axel Beckert
2013-07-03  8:57 ` Peter Stephenson

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