zsh-workers
 help / color / mirror / code / Atom feed
* Re: the mv trap
       [not found] ` <20070813023540.GC6199@prunille.vinc17.org>
@ 2007-08-13  7:44   ` zzapper
  2007-08-13 14:34     ` Vincent Lefevre
  0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2007-08-13  7:44 UTC (permalink / raw)
  To: zsh-workers; +Cc: zsh-users

Vincent Lefevre <vincent@vinc17.org> wrote in
news:20070813023540.GC6199@prunille.vinc17.org: 

> On 2007-08-12 20:57:13 +0000, zzapper wrote:
>> Hi

>> 
>> > mv x1 x2 x3 x4 x5 directory
> 
> Your mv is buggy. It must report the error and must not do any change
> on your files.
> 
Hi,
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





-- 
zzapper
http://www.rayninfo.co.uk/vimtips.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: the mv trap
  2007-08-13  7:44   ` the mv trap zzapper
@ 2007-08-13 14:34     ` Vincent Lefevre
  2007-08-13 16:50       ` Stephane Chazelas
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Lefevre @ 2007-08-13 14:34 UTC (permalink / raw)
  To: zsh-workers, zsh-users

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.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: the mv trap
  2007-08-13 14:34     ` Vincent Lefevre
@ 2007-08-13 16:50       ` Stephane Chazelas
  0 siblings, 0 replies; 3+ messages in thread
From: Stephane Chazelas @ 2007-08-13 16:50 UTC (permalink / raw)
  To: zsh-workers, zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-13 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Xns998ADF1A94C0Dzzappergmailcom@80.91.229.5>
     [not found] ` <20070813023540.GC6199@prunille.vinc17.org>
2007-08-13  7:44   ` the mv trap zzapper
2007-08-13 14:34     ` Vincent Lefevre
2007-08-13 16:50       ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).