zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: How to add a 'non-escaped' tilde to the completion list
Date: Mon, 10 Nov 2014 11:31:36 +0000	[thread overview]
Message-ID: <20141110113136.34766361@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <1415617649.1260.4.camel@gmail.com>

On Mon, 10 Nov 2014 12:07:29 +0100
Death Jester <d3ath.jest3r@gmail.com> 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


  reply	other threads:[~2014-11-10 11:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-10 11:07 Death Jester
2014-11-10 11:31 ` Peter Stephenson [this message]
2014-11-10 12:18   ` Peter Stephenson
2014-11-10 13:21     ` Death Jester
2014-11-10 13:42       ` Peter Stephenson
2014-11-10 13:57       ` Oliver Kiddle
2014-11-10 15:32         ` Death Jester
2014-11-10 21:03           ` Oliver Kiddle
2014-11-11 10:17             ` Death Jester
2014-11-11 21:40             ` Jan Larres
2014-11-10 12:54   ` Death Jester

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=20141110113136.34766361@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).