From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6327 invoked from network); 13 Aug 2007 16:50:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 13 Aug 2007 16:50:59 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 26574 invoked from network); 13 Aug 2007 16:50:53 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 13 Aug 2007 16:50:53 -0000 Received: (qmail 28193 invoked by alias); 13 Aug 2007 16:50:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23754 Received: (qmail 28177 invoked from network); 13 Aug 2007 16:50:51 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 13 Aug 2007 16:50:51 -0000 Received: (qmail 26288 invoked from network); 13 Aug 2007 16:50:50 -0000 Received: from smtpout0144.sc1.he.tucows.com (HELO n068.sc1.he.tucows.com) (64.97.136.144) by a.mx.sunsite.dk with SMTP; 13 Aug 2007 16:50:44 -0000 Received: from sc.homeunix.net (82.26.167.42) by n068.sc1.he.tucows.com (7.2.069.1) id 46A9389E001305D7; Mon, 13 Aug 2007 16:50:41 +0000 Received: from chazelas by sc.homeunix.net with local (Exim 4.67) (envelope-from ) id 1IKd7g-00041z-70; Mon, 13 Aug 2007 17:50:32 +0100 Date: Mon, 13 Aug 2007 17:50:32 +0100 From: Stephane Chazelas To: zsh-workers@sunsite.dk, zsh-users@sunsite.dk Subject: Re: the mv trap Message-ID: <20070813165032.GB5613@sc.homeunix.net> Mail-Followup-To: zsh-workers@sunsite.dk, zsh-users@sunsite.dk References: <20070813023540.GC6199@prunille.vinc17.org> <20070813143452.GE6199@prunille.vinc17.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20070813143452.GE6199@prunille.vinc17.org> User-Agent: Mutt/1.5.6i On Mon, Aug 13, 2007 at 04:34:52PM +0200, Vincent Lefevre wrote: > On 2007-08-13 07:44:39 +0000, zzapper wrote: > > red face; in fact my mv does report "not a directory". > > My problem is reduced to unintentionally moving a single file to another > > single file rather than the intended directory. > > > > MM solves this by suggesting a trailing slash > > > > $ mv x3 bucket/ > > mv: accessing `bucket/': Not a directory > > If you fear to forget the trailing slash, you can also write a shell > script/function that checks that the target is a directory, then > executes mv. [...] The thing is you sometimes do want to rename files with mv. The wrapper function could be made so as to check if there doesn't exist a directory spelled like the last argument. Something like: mv() { local dest=$@[-1] if [[ ! -d $dest ]]; then local -a files setopt localoptions extendedglob files=((#a2)$dest(ND/)) if (($#files)); then printf >&2 '"%s" doesn'\''t exist as a directory but\n' ${(V)dest} printf >&2 'there exist %d directory(ies) with a close name:\n' $#files local i for ((i = 1; i <= $#files; i++)); do printf >&2 ' %d "%s"\n' "$i" ${(V)files[i]} done printf >&2 'Would you like to move files to one of those instead (n12.)? [n] ' local answer read answer if [[ $answer = [0-9]## ]]; then argv[-1]=$files[answer] set -x fi fi fi command mv "$@" } -- Stéphane