From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11680 invoked by alias); 10 Nov 2014 12:59:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19360 Received: (qmail 11305 invoked from network); 10 Nov 2014 12:59:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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== X-Received: by 10.180.75.179 with SMTP id d19mr30508712wiw.21.1415624046013; Mon, 10 Nov 2014 04:54:06 -0800 (PST) Message-ID: <1415624044.1260.6.camel@gmail.com> Subject: Re: How to add a 'non-escaped' tilde to the completion list From: Death Jester To: zsh-users@zsh.org Date: Mon, 10 Nov 2014 13:54:04 +0100 In-Reply-To: <20141110113136.34766361@pwslap01u.europe.root.pri> References: <1415617649.1260.4.camel@gmail.com> <20141110113136.34766361@pwslap01u.europe.root.pri> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.7-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit 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 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