From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1211 invoked by alias); 11 Apr 2013 07:22: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: 17756 Received: (qmail 5786 invoked from network); 11 Apr 2013 07:22:40 -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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at de.ibm.com designates 195.75.94.112 as permitted sender) Subject: Automatic completion on X-KeepSent: C3CCF1B0:362C13EF-C1257B4A:00267D76; type=4; name=$KeepSent To: zsh-users@zsh.org X-Mailer: Lotus Notes Release 8.5.3 September 15, 2011 Message-ID: From: Dominik Vogt Date: Thu, 11 Apr 2013 09:12:16 +0200 X-MIMETrack: Serialize by Router on D06ML035/06/M/IBM(Release 8.5.3FP2 ZX853FP2HF3|December 12, 2012) at 11/04/2013 09:12:16 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13041107-3548-0000-0000-0000050AFE09 I already have a "smart" cd-script that allows to "cd" into files: cd with 0 parameters: Unchanged. cd with 1 parameters: If the parameter is a directory name, cd into it. If the parameter is a file name, cd into the directory containing the file. If the parameter is a file name that ends with .tar.gz, .tgz etc. and a directory with the same name without the suffix exists, cd into that (i.e. cd into extracted archives). cd with 2 parameters: I've forgotten what this does. That stuff does not look like my coding style. :-) 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? I've another idea how to extend this, but I'll write another message for that. -- BEGIN custom cd function cd () { case $# in 0) builtin cd ;; 1) VAR="$1" DIR=`dirname "$1"` if [[ -d "$1" ]]; then builtin cd "$1" elif STRIP="$DIR/`basename \"$VAR\" :`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .tar.gz`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .tar.bz2`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .tgz`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .TGZ`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .zip`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif STRIP="$DIR/`basename \"$VAR\" .ZIP`" && [[ -d "$STRIP" ]]; then builtin cd "$STRIP" elif [[ -f "$1" ]]; then builtin cd "$DIR" elif STRIP="$VAR[$#VAR]" && [[ -f "$STRIP" ]]; then builtin cd "$DIR" else builtin cd "$1" fi ;; 2) integer i=0 local target="$1" if ((ARGC > 1)); then while ((++i)) && [[ "$PWD" != "${(SI-$i-)PWD#${(q)1}}" ]] do target="${(SI-$i-)PWD/${(q)1}/$2}" [[ -d "$target" && -r "$target" ]] && break target="${(SI-$i-)PWD//${(q)1}/$2}" [[ -d "$target" && -r "$target" ]] && break target= done fi builtin cd "${target:-${PWD/${(q)1}/$2}}" ;; **) builtin cd "$@" ;; esac } -- END custom cd Ciao Dominik ^_^ ^_^