From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2489 invoked by alias); 11 Apr 2013 16:51:22 -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: 17758 Received: (qmail 12682 invoked from network); 11 Apr 2013 16:51:21 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130411095100.ZM9077@torch.brasslantern.com> Date: Thu, 11 Apr 2013 09:51:00 -0700 In-reply-to: Comments: In reply to Dominik Vogt "Automatic completion on " (Apr 11, 9:12am) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Automatic completion on MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Apr 11, 9:12am, Dominik Vogt wrote: } Subject: Automatic completion on } } I've another idea how to extend this, but I'll write another message } for that. I think your Subject on this message is actually about the other message? } I already have a "smart" cd-script that allows to "cd" into files: } [...] } } Now I wonder how this logic could be extended to work with the autocd } option. Is it possible to augment command execution with a script. Is } there any "hook" function that is automatically called if a command } from the command line cannot be executed because it does not exist? There is a command_not_found_handler shell function, but you can't use it for this because it doesn't run until after the parent shell has forked once to attempt to execute an external command. You might be able to do something in the zle-line-finish widget: zle-line-finish() { setopt localoptions no_nomatch no_nullglob no_cshnullglob set -- ${(z)BUFFER} if (( $# <= 2 )) && [[ ! -x =$1 ]] then BUFFER="cd $BUFFER" fi } zle -N zle-line-finish This won't work for "automatic cd" attempts buried inside multi-line constructs, etc., and you probably want some additional tests to avoid having this fire on the first line of a multi-line input or when there is an unmatched quote. Once you have it right, you could change BUFFER="cd $BUFFER" to be cd "$@" && BUFFER= but you likely don't want that to excute at the PS2 prompt (for example). For your enhancement of this idea, you could override the accept-line widget to do a similar test and invoke completion on the first word before (or instead of) actually accepting the line. This would require something along the lines of CURSOR=$#1 zle complete-word and then grab the BUFFER contents again and repeat the -x test. -- Barton E. Schaefer