9 B<vidir> [--verbose] [directory|file|-] ...
13 vidir allows editing of the contents of a directory in a text editor. If no
14 directory is specified, the current directory is edited. Each item in the
15 directory is listed. Delete items to remove them from the directory, or
16 edit their names to rename them.
18 Note that if "-" is specified as the directory to edit, it reads a list of
19 filenames from stdin and displays those for editing. Alternatively, a list
20 of files can be specified on the command line.
28 Verbosely display the actions taken by the program.
32 =head1 ENVIRONMENT VARIABLES
38 Editor to use. Defaults to vi if not set.
42 Also supported to determine what editor to use.
48 Does not support deletion of directories. Does not support recursive
49 editing of contents of a directory.
53 Copyright 2006 by Joey Hess <joey@kitenet.net>
55 Licensed under the GNU GPL.
65 if (! GetOptions
("verbose|v" => \
$verbose)) {
66 die "Usage: $0 [--verbose] [directory|file|-]\n";
73 foreach my $item (@ARGV) {
75 push @dir, map { chomp; $_ } <STDIN
>;
77 open(STDIN
, "/dev/tty") || die "reopen: $!\n";
80 opendir(DIR
, $item) || die "$0: cannot read $item: $!\n";
81 push @dir, sort readdir(DIR
);
89 my $tmp=File
::Temp
->new(template
=> "dirXXXXX");
90 open (OUT
, ">".$tmp->filename) || die "$0: cannot write ".$tmp->filename.": $!\n";
95 next if $_ eq '.' || $_ eq '..';
97 print OUT
"$c.\t$_\n";
103 if (exists $ENV{EDITOR
}) {
104 $editor=$ENV{EDITOR
};
106 if (exists $ENV{VISUAL
}) {
107 $editor=$ENV{VISUAL
};
109 $ret=system($editor, $tmp);
111 die "$editor exited nonzero, aborting\n";
114 open (IN
, $tmp->filename) || die "$0: cannot read ".$tmp->filename.": $!\n";
117 if (/^(\d+)\.\t(.*)/) {
120 if (! exists $item{$num}) {
121 print STDERR
"$0: unknown item number $num\n";
124 elsif ($name ne $item{$num}) {
128 if (-e
$name || -l
$name) {
131 while (-e
$tmp || -l
$tmp) {
135 if (! rename($name, $tmp)) {
136 print STDERR
"$0: failed to rename $name to $tmp: $!\n";
140 print "'$name' -> '$tmp'\n";
142 foreach my $item (keys %item) {
143 if ($item{$item} eq $name) {
149 if (! rename($src, $name)) {
150 print STDERR
"$0: failed to rename $src to $name: $!\n";
154 print "'$src' -> '$name'\n";
160 die "$0: unable to parse line \"$_\", aborting\n";
164 unlink($tmp.'~') if -e
$tmp.'~';
166 foreach my $item (sort values %item) {
167 if (! unlink($item)) {
168 print STDERR
"$0: failed to remove $item: $!\n";
172 print "removed '$item'\n";