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

Re: avoid interpretation of special characters



On Thu, Dec 06, 2007 at 11:11:49AM +0100, Eric Smith wrote:
> For my command (say mut), I want to avoid shell interpretation of
> characters like ~ and > or <
> so when I go mut  ~f foo and ~r <2w ~r >1w
> I want those characters passed literally to the script.
> (instead of obviously have to use backslash or quotes for this
> purpose.
[...]

Does that include spaces. Do you want everything past the first
space to be passed to "mut" in one single argument?

you could do something like:

alias mut=':;#'
setopt interactivecomments
check-for-mut() {
  if [[ $1 = "mut "* ]]; then
    command mut "${1#mut }"
  fi
}
preexec_functions+=(check-for-mut)

(not tested).

Alternatively, you could redefine the accept-line widget so that
it inserts quotes were needed.

accept-line() {
  if [[ $BUFFER = "mut "* ]]; then
    BUFFER="mut ${(qq)BUFFER#mut }"
  fi
  zle .accept-line
}
zle -N accept-line

-- 
Stephane



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