Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "Edit" files names



Yuri D'Elia <wavexx@xxxxxxxxxx> writes:

> Hi everyone,
>
> Let's assume I have a garbled file name that I want to rename more
> conveniently into an editor, without painful escaping.
>
> I'd like to do the following:
>
> $ editname *garbled*
>
> popping my $EDITOR with a file containing the original file name
> (unescaped), and upon saving+closing, renames the original into the new
> name provided. If the pattern expands to more files, it just repeats for
> each file, in turn.
>
> It's not hard to implement, but does anybody know of a tool which
> already does that (or something very similar)?

Not exactly what you asked for, but I like this (uses ZLE):

# imv -- interactive rename, using vared
imv() {
  local src dst
  for src; do
    [[ -e $src ]] || { print -u2 "$src does not exist"; continue }
    dst=$src
    vared dst
    [[ $src != $dst ]] && mkdir -p $dst:h && mv -n $src $dst &&
      print -s mv -n $src:q:q $dst:q:q   # save to history, thus M-. works
  done
}


-- 
Leah Neukirchen  <leah@xxxxxxxx>  http://leah.zone



Messages sorted by: Reverse Date, Date, Thread, Author