Git Product home page Git Product logo

vimv's Introduction

vimv

vimv is a terminal-based file rename utility that lets you easily mass-rename files using Vim.

Installing

  1. For the current user:
    curl https://raw.githubusercontent.com/thameera/vimv/master/vimv > ~/.local/bin/vimv && chmod +755 ~/.local/bin/vimv
    
  2. For the current system:
    sudo PREFIX=/usr/local make install
    

Or simply copy the vimv file to a location in your $PATH and make it executable.

Usage

  1. Go to a directory and enter vimv with optionally, a list of files to rename.
  2. A Vim window will be opened with names of all files.
  3. Use Vim's text editing features to edit the names of files. For example, search and replace a particular string, or use visual selection to delete a block.
  4. Save and exit. Your files should be renamed now.

Other features

  • If you want to list only a group of files, you can pass them as an argument. eg: vimv *.mp4
  • If you have an $EDITOR environment variable set, vimv will use its value by default.
  • If you are inside a Git directory, vimv will use git mv (instead of mv) to rename the files.
  • You can use /some/path/filename format to move the file elsewhere during renaming. If the path is non-existent, it will be automatically created before moving.

Screencast

alt text

Gotchas

Don't delete or swap the lines while in Vim or things will get ugly.

Running tests

Tests are written using bats. To run the tests:

git submodule update --init
test/test_vimv.bats

vimv's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vimv's Issues

Don't overwrite files.

Input:

o1_foo.png
o1_bar.png
o1_baz.png
o2_baz.png

ls | wc -l # 4
vimv transform:

foo.png
bar.png
baz.png
bar.png

result:

foo.png
bar.png
baz.png

Either fail, or present the conflicted files (with possibly the original name as well, bonus points for checksum) only the second time.

Python 3 compatibility

Hi,

I really like vimv, but had to hack it to work with py3. It works for me but I think might like py3 compatibility as well.

Cheers!

ability to sort the files in created/modified time

I often use vimv to number files from abc, xyz to 01.abc 02.xyz etc. using macros
However, by default the vimv buffer displays all files in natural/alphanumeric sort.
Any support to sort the files according to ctime or mtime would be great :)

Opens with Nano instead of Vim

I'm not sure what the problem is, but whenever I open vimv, it opens with Nano instead of Vim. I can use Nano no problem, but it's just a bit of an annoyance when Vim has so much more functionality, and when this is supposed to open Vim.

File order matters. Files can be overwritten unexpectedly.

Steps to reproduce:

  1. Run for i in $(seq 0 9); do touch "file ($i).txt"; done
  2. Run vimv *
  3. Rename the 10 files from
    file (0).txt
    file (1).txt
    file (2).txt
    file (3).txt
    file (4).txt
    file (5).txt
    file (6).txt
    file (7).txt
    file (8).txt
    file (9).txt
    
    to
    file (1).txt
    file (2).txt
    file (3).txt
    file (4).txt
    file (5).txt
    file (6).txt
    file (7).txt
    file (8).txt
    file (9).txt
    file (10).txt
    
  4. All that's left is file (10).txt ๐Ÿ˜ข

Confirm deletions; confirm all actions

Allow to specify an option, to optionally (maybe by default) confirm deletions and/or renames:

old_file โ†’ new_file

The outputs can be colored as well.

I'd prefer multi-line output, git style.

If the list is long, or always, use less to not flood the screen.

Abort if an input file has a newline in its name

If an input file contains a newline, there's no way to distinguish between
that newline and the newline the terminates the file name in the editor buffer.

While workarounds exist (for example, separate the file names with null bytes),
I'm not sure how that would affect the usability of the script without significant
editor-specific configuration.

I would recommend simply aborting if any source name contains a newline, letting
the caller deal with the issue manually.

Does not honor $TMPDIR (PR included)

vimv assumes /tmp as the temporary directory. It isn't the case on some systems, like Android's Termux (actually, this is probably Android's fault and not Termux', come to think of it).

$TMPDIR is a commonly used variable to indicate where the temporary directory is in this system, or may be what directory the user wants you to use (Wikipedia, Ubuntu's Wiki).

On the other hand, you can't just use TMPDIR without a default, because some other systems don't set it, like Ubuntu on WSL. I that case I suggest vimv should go on using /tmp, which is the most common and actually what Ubuntu on WSL uses.

Here is a PR: #12

PD: By the way, I love vimv and use it every day, thanks!

Make a release

I think using releases would make it simpler for people to package this for Linux distributions.

The program aborts on first rename

Issue Description

8ee5d21 introduces the set -eu command that instructs the script to terminate on first exit with a non-zero status.

But this line poses a problem:

vimv/vimv

Line 35 in 6944224

((count++))

Because if you look at (( help page, it says:

Exit Status:
Returns 1 if EXPRESSION evaluates to 0; returns 0 otherwise.

Since ((count++)) increases the variable returning its previous value, and count begins at 0, first ((count++)) returns 1 like the help page says, because the expression evaluates to 0. This causes the program to terminate prematurely on first rename.

Steps to reproduce

This ZIP archive contains the example from the README (all the files are just empty files created by touch). To reproduce the issue, try to follow the example by removing Rick and Morty using visual block. After proceeding you will see that only the first file (S01E01 Pilot.mp4) has been renamed.

Solution

The solution to this problem is very simple, just change the order of ++ so that the expression doesn't evaluate to 0:

((++count))

And this is exactly what my referenced pull request does.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.