Convenient interactive renaming in zsh

While risking turning this into the renaming files blog I just used another one of my favorite functions that I’ve named iren and realized it could be worth sharing as well. This one is really simple to put together when using zsh. It will allow you to type iren file1 file2 ... and for each file name specified you will get to interactively edit the file name using the normal line editing features in zsh. When you’re done you press enter and the file is renamed/moved. If you haven’t tried it before I can really recommend zsh, it used to be the best shell by far, although bash has caught up on many areas. iren uses the built-in zsh function vared that can be used to interactively edit any environment variable. Here’s the iren function, put it in your .zshrc file:

function iren ()
{
        while [ "$1" != "" ]
        do
                source=$1
                dest=$1
                vared dest
                if [ "$source" != "$dest" ]
                then
                        mv "$source" "$dest"
                fi
                shift
        done
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>