From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5420 invoked by alias); 14 Aug 2011 19:57:54 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29684 Received: (qmail 29271 invoked from network); 14 Aug 2011 19:57:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at sebastian.tramp.name does not designate permitted sender hosts) Date: Sun, 14 Aug 2011 21:57:42 +0200 From: Sebastian Tramp To: Bart Schaefer Cc: zsh-workers@zsh.org Subject: Re: starting completion / command history Message-ID: <20110814195742.GA12477@soljaris7.fritz.box> Mail-Followup-To: Bart Schaefer , zsh-workers@zsh.org References: <20110811211150.GA21221@soljaris7.fritz.box> <110811190809.ZM6937@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <110811190809.ZM6937@torch.brasslantern.com> X-PGP-Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE8093B579D601B44 X-FOAF: http://sebastian.tramp.name User-Agent: Mutt/1.5.21 (2010-09-15) On Thu, Aug 11, 2011 at 07:08:09PM -0700, Bart Schaefer wrote: Bart, thank you very much for this snippet (and the notes!!). It works exact as I wanted and I can now concentrate on how commands are saved and which commands are displayed in which directories. big fat kudo :) seebi > On Aug 11, 11:11pm, Sebastian Tramp wrote: > } > } Is there a way to map a at the beginning of a command line to a > } completion function? > > What you need to do is bind tab to a non-completion zle widget so you > can examine the cursor position, then invoke the appropriate completion > widget depending on where you are. > > overload-tab () { > if (( CURSOR < 1 )) > then zle your-new-widget > else zle expand-or-complete > fi > } > zle -N overload-tab > bindkey $'\t' overload-tab > > Next of course you need to define your-new-widget. > > } I want to use it to complete full command lines which I save as a > } history for each directory so that I can re-use commonly executed > } commands (incl. parameters) for a specific directory. > > The problem with this scheme is that completion is EXTREMELY word- > oriented. As soon as you introduce a command line containing spaces > and/or quotes and/or punctuation, completion is likely to become very > confused. > > I've actually implemented something basically like this and the only > way I got it to work reasonably reliably was (a) bind it to something > other than TAB and (b) force it directly into menu selection so you > have to choose the command by navigation. It's pretty simple and > looks like this: > > -- 8< -- snip -- 8< -- > #compdef -k menu-complete ^X: > zmodload -i zsh/complist > _cmdselect() { > local -a commands > commands=(${(f)"$(< ~/.cmdselect)"}) > compadd -Qa commands > MENUSELECT=0 > compstate[insert]=menu > } > _cmdselect "$@" > -- 8< -- snip -- 8< -- > > Note the #compdef line to automatically bind this to ctrl-x colon. > Also note the use of compadd -Q to insert the selection without turning > into a monolithic quoted word. -- Sebastian Tramp WebID: http://sebastian.tramp.name