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

Re: Expanding quotes



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



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