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

Re: How to add a 'non-escaped' tilde to the completion list



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