zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Expanding quotes
Date: Tue, 24 Dec 2013 22:59:37 -0800	[thread overview]
Message-ID: <131224225937.ZM766@torch.brasslantern.com> (raw)
In-Reply-To: <l9cbmk$6od$1@ger.gmane.org>

On Dec 24,  5:11pm, Yuri D'Elia wrote:
}
} Personally, I would actually prefer is there was an option in zsh to
} normalize the quoting mechanism to always "double quote" the argument
} instead of escaping characters (thus inserting the initial double-quote
} if missing). I don't know if this would actually simplify or furthermore
} complicate the expansion rules.

Have a look at Functions/Zle/quote-and-complete-word in the distributed
sample functions.

} the fact that a glob might not expand in the same way as when executed
} makes a bit of uneasy feeling for me. I often use expansion to
} proof-check a glob instead of executing the command twice.
} 
} Maybe there's a better way to do it that doesn't involve running "ls
} glob" before "real-command glob".

You can create your own little completer that does nothing but globbing:

    _glob () {
      local -a globbed
      globbed=( ${(Q)~words[CURRENT]} )
      [[ $globbed == $words[CURRENT]] ]] && return 1
      compadd -Uf -a globbed
    }

You can fiddle with the assignment to globbed until you get the behavior
you want.  What I've done with ${(Q)~words[CURRENT]} may not be to your
liking; e.g. you might prefer ${~words[CURRENT]//\\/} to only remove any
backslashes.  Something of the kind is needed, though, because the tilde
operator only makes globbing characters active, it doesn't unquote other
special characters that may be quoted in the value of $words.

The default completers if you don't set a style are (_complete _ignored).
So you just need to add yours:

    zstyle ':completion:*' completer _glob _complete _ignored

(Use "zstlyle -L" to see if you've already changed the completer style,
and if so just add _glob in an appropriate place.)


      reply	other threads:[~2013-12-25  6:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 14:48 Yuri D'Elia
2013-12-17 18:26 ` Bart Schaefer
2013-12-23 17:38   ` Yuri D'Elia
2013-12-23 19:15     ` Bart Schaefer
2013-12-24 15:12       ` Ray Andrews
2013-12-24 16:24         ` Yuri D'Elia
2013-12-24 17:18           ` Ray Andrews
2013-12-26 14:50             ` Yuri D'Elia
2013-12-26 19:54               ` Ray Andrews
2013-12-24 16:11       ` Yuri D'Elia
2013-12-25  6:59         ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=131224225937.ZM766@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).