format new perl scripts
This commit is contained in:
parent
201d5e9edf
commit
07ff52dfdd
2 changed files with 56 additions and 56 deletions
.local/bin
|
@ -27,8 +27,9 @@ sub trash_dirs($file_fs_root) {
|
||||||
my $trash_dir;
|
my $trash_dir;
|
||||||
if ( $file_fs_root eq fs_root($data_path) ) {
|
if ( $file_fs_root eq fs_root($data_path) ) {
|
||||||
$trash_dir = "$data_path/Trash/";
|
$trash_dir = "$data_path/Trash/";
|
||||||
} else {
|
}
|
||||||
$trash_dir = "$file_fs_root/.Trash/"
|
else {
|
||||||
|
$trash_dir = "$file_fs_root/.Trash/";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "${trash_dir}info", "${trash_dir}files";
|
return "${trash_dir}info", "${trash_dir}files";
|
||||||
|
@ -36,7 +37,8 @@ sub trash_dirs($file_fs_root) {
|
||||||
|
|
||||||
sub target_file_name ( $file_name, $trash_file_path ) {
|
sub target_file_name ( $file_name, $trash_file_path ) {
|
||||||
opendir( my $dir, "$trash_file_path" ) or die "$!\n";
|
opendir( my $dir, "$trash_file_path" ) or die "$!\n";
|
||||||
my $existing_suffix_nums = map(($_ =~ /^${file_name}\.~(\d)~/), readdir $dir);
|
my $existing_suffix_nums =
|
||||||
|
map( ( $_ =~ /^${file_name}\.~(\d)~/ ), readdir $dir );
|
||||||
my $suffix_num = max($existing_suffix_nums) + 1;
|
my $suffix_num = max($existing_suffix_nums) + 1;
|
||||||
my $suffix = "~" . $suffix_num . "~";
|
my $suffix = "~" . $suffix_num . "~";
|
||||||
closedir($dir);
|
closedir($dir);
|
||||||
|
|
|
@ -24,25 +24,20 @@ sub trashed_files($search_path, $trash_path) {
|
||||||
opendir( my $dir, "$trash_path/info" ) or die "$!\n";
|
opendir( my $dir, "$trash_path/info" ) or die "$!\n";
|
||||||
for ( readdir $dir ) {
|
for ( readdir $dir ) {
|
||||||
$_ =~ /\.~\d~$/ or next;
|
$_ =~ /\.~\d~$/ or next;
|
||||||
|
|
||||||
open( FH, "<", "$trash_path/info/$_" ) or next;
|
open( FH, "<", "$trash_path/info/$_" ) or next;
|
||||||
|
|
||||||
<FH> eq "[Trash Info]\n" or next;
|
<FH> eq "[Trash Info]\n" or next;
|
||||||
|
my ( $name, $path, $suffix ) =
|
||||||
my ($name, $path, $suffix) = fileparse((<FH> =~ /(?<=Path=)(.+)$/)[0]);
|
fileparse( ( <FH> =~ /(?<=Path=)(.+)$/ )[0] );
|
||||||
$path =~ /^$search_path\/?$/ or next;
|
$path =~ /^$search_path\/?$/ or next;
|
||||||
|
|
||||||
my $deletion_date = ( <FH> =~ /(?<=DeletionDate=)(.+)$/ )[0];
|
my $deletion_date = ( <FH> =~ /(?<=DeletionDate=)(.+)$/ )[0];
|
||||||
chomp( $deletion_date = `date -d ${deletion_date} +'%x %X'` );
|
chomp( $deletion_date = `date -d ${deletion_date} +'%x %X'` );
|
||||||
push( @ret, [ $path, "${name}${suffix}", $deletion_date, $_ ] );
|
push( @ret, [ $path, "${name}${suffix}", $deletion_date, $_ ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
return @ret;
|
return @ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fzf_files (@files) {
|
sub fzf_files (@files) {
|
||||||
my $n = 0;
|
my $n = 0;
|
||||||
|
|
||||||
my $str;
|
my $str;
|
||||||
for my $e (@files) {
|
for my $e (@files) {
|
||||||
$str .= "\n" if $n > 0;
|
$str .= "\n" if $n > 0;
|
||||||
|
@ -61,11 +56,13 @@ sub fzf_files(@files) {
|
||||||
my $target_directory;
|
my $target_directory;
|
||||||
if ( $#ARGV + 1 > 1 ) {
|
if ( $#ARGV + 1 > 1 ) {
|
||||||
die "Bad Arguments\n";
|
die "Bad Arguments\n";
|
||||||
} elsif ($#ARGV + 1 == 1) {
|
}
|
||||||
|
elsif ( $#ARGV + 1 == 1 ) {
|
||||||
$target_directory = shift;
|
$target_directory = shift;
|
||||||
chomp( $target_directory = `realpath -s $target_directory` );
|
chomp( $target_directory = `realpath -s $target_directory` );
|
||||||
stat $target_directory or die "$!\n";
|
stat $target_directory or die "$!\n";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$target_directory = getcwd();
|
$target_directory = getcwd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,5 +74,6 @@ my $index = fzf_files(@files);
|
||||||
my $file_dest = $files[$index][0] . $files[$index][1];
|
my $file_dest = $files[$index][0] . $files[$index][1];
|
||||||
my $file_src = $trash_dir . "files/" . $files[$index][3];
|
my $file_src = $trash_dir . "files/" . $files[$index][3];
|
||||||
my $file_info = $trash_dir . "info/" . $files[$index][3];
|
my $file_info = $trash_dir . "info/" . $files[$index][3];
|
||||||
|
|
||||||
move( $file_src, $file_dest ) or die "$!\n";
|
move( $file_src, $file_dest ) or die "$!\n";
|
||||||
unlink($file_info);
|
unlink($file_info);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue