Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Command not found handler for non-searched commands?
- X-seq: zsh-users 17043
- From: "Benjamin R. Haskell" <benizi@xxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Command not found handler for non-searched commands?
- Date: Sun, 29 Apr 2012 13:00:45 -0400 (EDT)
- In-reply-to: <alpine.LNX.2.01.1204291251150.27115@hp.internal>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <alpine.LNX.2.01.1204291213180.27115@hp.internal> <alpine.LNX.2.01.1204291251150.27115@hp.internal>
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:
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
Now $dir ends up containing '~/tmp/one-off-project', with the '~' 
unexpanded.  Seeing as how the directory doesn't yet exist, I can't 
just glob it.  Is there a function to do just named-directory 
expansion?
Answered my own question, kind of...  I found the '~' parameter 
expansion flag.  Still don't 100% understand why pattern expansion 
(terminology?) is different than globbing w.r.t. non-existent files. 
Final solution ended up as the following (Difference is the 'dir=${~1}' 
line):
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
--
Best,
Ben
Messages sorted by:
Reverse Date,
Date,
Thread,
Author