summaryrefslogtreecommitdiff
path: root/dot
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-09-11 15:42:51 -0400
committerAndrew Cady <d@jerkface.net>2018-09-11 15:42:51 -0400
commit8a448e9321e29d6779f4f4b76bc4c10ebb6c620b (patch)
tree3d941af3921fdc422ca30f68ef9f2cb57cc34639 /dot
parentf864cade7f6dcdb7aef4fbcdb6ac17c008a09e03 (diff)
interactive-rename
Diffstat (limited to 'dot')
-rwxr-xr-xdot/local/bin/interactive-rename28
1 files changed, 28 insertions, 0 deletions
diff --git a/dot/local/bin/interactive-rename b/dot/local/bin/interactive-rename
new file mode 100755
index 0000000..e8017c7
--- /dev/null
+++ b/dot/local/bin/interactive-rename
@@ -0,0 +1,28 @@
1#!/usr/bin/perl -w
2use File::Temp ();
3$tmp = new File::Temp(UNLINK=>1);
4
5# TODO:
6# escape & unescape linefeeds
7# handle nonexistent files better
8# handle system() errors
9
10@ARGV = grep {-e $_} @ARGV;
11die "No files!\n" unless @ARGV;
12
13for (@ARGV) {
14 m(\n) && die "Sorry - can't do filenames with linefeeds (yet)\n";
15 print $tmp "$_\n";
16}
17
18$editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
19system($editor, $tmp) == 0 or die;
20
21seek($tmp, 0, 0) or die "seek: $!";
22@newname = <$tmp>;
23chomp for @newname;
24die "number of names changed!\n" unless @newname == @ARGV;
25
26for (0 .. $#ARGV) {
27 rename($ARGV[$_], $newname[$_]) unless $ARGV[$_] eq $newname[$_];
28}