Vidir: Difference between revisions
m
→{{header|Raku}}: Bug fix, rename some variables minor tweaks
Thundergnat (talk | contribs) m (→{{header|Raku}}: twiddles) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Bug fix, rename some variables minor tweaks) |
||
Line 131:
'''Named:'''
* '''-r'''
* '''-v'''
* '''--
Line 158:
unit sub MAIN (
Str $path = '.', #= default $path
Str $filter = '', #= default file filter
Bool :
Bool :
Str :e(:$editor) = $*DISTRO ~~ /'Darwin'/ ?? "open" !! "xdg-open"; #= default editor
);
Line 173:
die "Can not find directory $dir" unless $dir.IO.d;
# get files from that path▼
my @files;
▲# get files from that path
getdir( $dir, $filter );
@files.= sort( &naturally );
# set up a temp file and file handle
my ($filename, $filehandle) = tempfile :suffix('.vidir');
# editor command▼
my $command = "$editor $filename";▼
# write the filenames to the tempfile
Line 190:
$filehandle.flush;
▲# editor command
# suppress STDERR, some editors complain about open files being deleted▼
▲my $command = "$editor $filename";
▲# start text editor; suppress STDERR, some editors complain about open files being deleted
shell("$command 2> /dev/null");
react {
# watch for file
whenever IO::Notification.watch-path($filename) {
# allow a short interval for the file to finish writing
Line 210 ⟶ 213:
checkdir %changes{"$k"};
# notify and do it
say "Renaming: {@files[$k]} to " ~ %changes{"$k"} if $
rename @files[$k], %changes{"$k"} orelse .die;
}
Line 218 ⟶ 221:
# name is gone, delete the file
# notify and do it
say "Deleting: {@files[$k]}" if $
@files[$k].unlink orelse .die;
}
Line 227 ⟶ 230:
checkdir $v;
# notify and do it
say "Adding: $v" if $
shell("touch $v") orelse .die;
}
Line 245 ⟶ 248:
sub files ( $dir, $filter = '' ) {
if $filter.chars {
$dir.IO.dir.grep( *.f ).grep( *.basename.contains(/<$filter>/)
} else {
$dir.IO.dir.grep( *.f
}
}
Line 253 ⟶ 256:
# get the files in the present directory and recurse if desired
sub getdir ($dir, $filter) {
if $
@files.append: files($dir, $filter);
getdir( $_, $filter ) for $dir.IO.dir.grep( *.d );
Line 269 ⟶ 272:
my $thispath = @path[^$_].join('/');
unless $thispath.IO.e {
say "Creating new directory $thispath" if $
mkdir($thispath);
}
|