From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12615 invoked by alias); 30 Apr 2012 01:34:45 -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: 17049 Received: (qmail 18153 invoked from network); 30 Apr 2012 01:34:33 -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 autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Sun, 29 Apr 2012 21:34:02 -0400 (EDT) From: "Benjamin R. Haskell" To: Zsh Users Subject: Re: Command not found handler for non-searched commands? In-Reply-To: Message-ID: References: User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed On Sun, 29 Apr 2012, Benjamin R. Haskell wrote: > On Sun, 29 Apr 2012, Benjamin R. Haskell wrote: > >> On Sun, 29 Apr 2012, Benjamin R. Haskell wrote: >> >> > I use autocd quite a bit. And often the first thing I want to do >> > when starting a new project is to create a directory and cd into >> > it. I tried creating the following command_not_found_handler: >> > >> Okay. Different tack, different problem: >> [...] > Final solution ended up as the following [...]: > > preexec { > __last_command=$1 > # ... etc. > } > > trap ' > local dir= create= > set -- ${=__last_command} > (( $# == 1 )) || return 1 > [[ $1 == */* ]] || return 1 > dir=${~1} > read -q "create?Create $dir [y/N]? " || return 1 > mkdir -p $dir || return 1 > cd $dir > ' ZERR Still talking to myself, but in case someone else follows my lead, I found fairly quickly that this wreaks havoc on unrelated non-zero error codes. (e.g. `false ; echo yay` does not echo 'yay'). After reading the section from the manual on: trap '' ZERR vs. TRAPZERR () { } yet again, I realized I shouldn't be calling 'return' explicitly (because it returns from the calling context). So, I'm now at: preexec { __last_command=$1 # ... etc. } trap ' local dir= choose= set -- ${=__last_command} if (( $# == 1 )) && [[ $1 == */* ]] ; then if read -q "choose?Create $1 [y/N]? " ; then dir=${~1} if mkdir -p $dir ; then cd $dir fi fi fi ' ZERR This still feels substantially heavier-weight than the command_not_found_handler I'd been hoping for. But, it seems to be working. -- Best, Ben