Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Prefixed backslash removed when completing command



On 2010-10-27 12:02, Peter Stephenson wrote:
On Wed, 27 Oct 2010 11:06:16 +0200
Mikael Auno<auno@xxxxxx>  wrote:
If I am not completely misunderstanding your reply, I think you
misunderstood my issue. My issue has nothing to do with either single
or double quotes (they are only there in the original message to
separate the examples from the rest of the text), but with the
backslash.

No, you've misunderstood my reply.

When I try to tab complete something starting with a leading
backslash, e.g. \mpla, then it is completed to mplayer (without a
leading backslash) instead of \mplayer (with a leading backslash) as
I would expect.

Yes, I realise that.  Here's my reply rephrased.

The internals of completion are complicated.  There is no prospect of it
ever being able to preserve quotations in a general way.  In particular
there is no prospect of it ever being able to retain backslashes that
have no basic syntactic effect.

Slight digression on what I mean by a "basic syntactic effect".  Aliases
are a special case as they are expanded on input, so things that are
usually ignored in the usual shell grammar become significant;
completion doesn't know anything about this.  Completion just tries to
muddle through and produce an expression that (ignoring the alias
problem) is quoted in an appropriate way for the shell to process the
word on the command line.

If quoting is done using backslashes the only backslashes left will be
those needed for special characters.  Completion makes no attempt to try
to remember how the original word looked and reconstruct it.

However, if quoting is done with a single or double quote character at
the start of the word, that form of quoting is preserved even if it's
not (apparently) needed to quote special characters.  In this case,
completion remembers the whole word is quoted.  This is much simpler
than trying to remember what happens character by character.

So if you really insist on having a backslash, you are stuck, as far as
completion is concerned.  (You still have the possibility of writing
line editor, non-completion, functions to quote the word how you want.)

However, *if* it happens to be the case that you are simply trying to
ensure the word is quoted, somehow, you can get away with starting it
with a single quote, and forget about the backslash.  The single quote
is preserved during completion, unlike the backslash, and a closing
quote appended.  So it all works, and you have completed a quoted word.

I'm not aware of anywhere in the shell that requires you to quote a word
as \mplayer rather than 'mplayer'.  They should have the same effect in
every case except the bizarre one where you have defined 'mplayer',
including the quotes, as an alias.  So if you started with a single
quote (I know that's not what you asked about) it should do the right
thing, or I'd like to hear why it doesn't.

You are completely correct. I misunderstood your reply as I did not know that the backslash was at all related to quoting or that ordinary quoting had the same result as prefixing a command with a backslash with respect to suppressing alias expansion. Prefixing with single or double quotes works great, especially as the closing quote is appended automatically.

Thank you for this insight,
Mikael Auno



Messages sorted by: Reverse Date, Date, Thread, Author