From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8956 invoked by alias); 10 Nov 2014 11:31:42 -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: 19358 Received: (qmail 27589 invoked from network); 10 Nov 2014 11:31:41 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f956d000005ed7-82-5460a219673e Date: Mon, 10 Nov 2014 11:31:36 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: How to add a 'non-escaped' tilde to the completion list Message-id: <20141110113136.34766361@pwslap01u.europe.root.pri> In-reply-to: <1415617649.1260.4.camel@gmail.com> References: <1415617649.1260.4.camel@gmail.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmluLIzCtJLcpLzFFi42I5/e/4FV3JRQkhBpf7BS12nFzJ6MDoserg B6YAxigum5TUnMyy1CJ9uwSujJn3FzMWLOSp6J2zlKmBcR5nFyMHh4SAicTNBVldjJxAppjE hXvr2boYuTiEBJYySqy9coARymGSWPZ1JhNIFYuAqsSsf//AbDYBQ4mpm2YzgtgiAqISy1ds ZgexhQVcJKY2fGQHWcArYC+xaXMMSJhTwEDi76ktYOVCAvoSD168YQOx+YHsq38/MUEcYS8x 88oZsBpeAUGJH5PvsYDYzAJaEpu3NbFC2PISm9e8ZZ7AKDALSdksJGWzkJQtYGRexSiaWppc UJyUnmukV5yYW1yal66XnJ+7iRESgF93MC49ZnWIUYCDUYmH1+NLfIgQa2JZcWXuIUYJDmYl Ed5rsxJChHhTEiurUovy44tKc1KLDzEycXBKNTC6fj81PX/e/YI7RuEc6VoTBCcuy5jcNen6 7tfBB/ky5YQ8es4rORRvO9V9m9dpvRxr9vYk30dF5RPKZWtnH7rau6JKqnlmQI/JtJdx2vGh wmZ6nmtYV+1U0WLacns+x+05KXN044+83T7/FsdvK+WOR5mXBLg++UY39Pq//fVGNXjlI4vk 3y5KLMUZiYZazEXFiQBox5AOHgIAAA== 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