Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to add a 'non-escaped' tilde to the completion list
- X-seq: zsh-users 19360
- From: Death Jester <d3ath.jest3r@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: How to add a 'non-escaped' tilde to the completion list
- Date: Mon, 10 Nov 2014 13:54:04 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:date:in-reply-to:references:content-type :mime-version:content-transfer-encoding; bh=kOjS9/K4OAR6+B5dTaPgs3xjlycSnsDrb4dJIbETWvU=; b=C1FRVph9kPkmwElYas7GbGCkxfUk99KSuw0wuMrZVsS0h7w6GWXVTBao1eRU+kDdJd hQwOgWsRH5bzYQUrsvkD23ims4Q+SGLPs9o5ZGZu352i9U2zfMieX9lDwwaa8vzI17Bi QVZgfFamkFF6TdlijxBQ2ucgb/56Nai6Kv3h36zan4kCdAZamQBD7XGsDu0opc/9hFm7 5qyDsAVkLUHdYh+dOjpUpPK17qo60dZSoDCaltcQjr0glEQm6NVhvhokKbDhakE+5wlm B9N0fehuP2dlFdyKeFEd6VleLLzx0PhInlMYd387wdx+Od1UiL/sd0r9mm/hlil4XvNu P3Yw==
- In-reply-to: <20141110113136.34766361@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1415617649.1260.4.camel@gmail.com> <20141110113136.34766361@pwslap01u.europe.root.pri>
Awesome, thank you Peter! Now it works. I extended my function in the
following way:
function _term_list(){
local -a w
for SESSION in $(pidof zsh); do
PA=$(readlink -n /proc/${SESSION}/cwd)
w+=(${(D)PA})
done
compadd -aQ w
}
And btw, also spaces are recognized correctly and are terminated with a
backslash in front of it, when inserted on the commandline.
Cheers,
Jester
On Mon, 2014-11-10 at 11:31 +0000, Peter Stephenson wrote:
> On Mon, 10 Nov 2014 12:07:29 +0100
> Death Jester <d3ath.jest3r@xxxxxxxxx> wrote:
>
> > Hi *,
> > I have the following completion function:
> >
> > function _term_list(){
> > local -a w
> >
> > for SESSION in $(pidof zsh); do
> > PA=$(readlink -n /proc/${SESSION}/cwd)
> > case ${PA} in
> > ${HOME}*) w+=$(echo ${PA} | sed s"|${HOME}|~|") ;;
> > *) w+=${PA} ;;
> > esac
> > done
> >
> > compadd -a w
> > }
> >
> > zle -C term_list complete-word _generic
> > bindkey "^v" term_list
> > zstyle ':completion:term_list:*' completer _term_list
>
> You can replace the whole case with:
>
> w+=(${(D)PA})
>
> which does the substitution you're after --- it substitues all named
> directories, in fact, not just $HOME, but presumably that's OK.
>
> Note you do need the parentheses when you're adding array elements,
>
> > But unfortunately the
> > line '${HOME}*) w+=$(echo ${PA} | sed s"|${HOME}|~|") ;;' does not work
> > as intended. The tilde is always "escaped". So the output looks like:
> > \~
> > \~/folder
> >
> > How can I remove the backslash.
>
> I presume you mean it's escaped when it's inserted on the command line.
>
> The short answer is you need to add the -Q flag to the compadd at the
> end of the function so that the name doesn't get quoted. However, you
> need to be a bit careful since that implies that you've already quoted
> the rest of the name (having spaces is the most common cause of grief).
>
> I'm sure there's some prior art on this in the completion system that
> others will remember better than me.
>
> pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author