From f9fea26aa3ead597b88827352f0575c0d589b336 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Sat, 4 May 2024 16:39:25 +0200 Subject: [PATCH] remove old scripts --- .local/bin/trash-put | 75 -------------------------------- .local/bin/trash-restore | 77 --------------------------------- .local/libexec/cron/trash-prune | 49 --------------------- 3 files changed, 201 deletions(-) delete mode 100755 .local/bin/trash-put delete mode 100755 .local/bin/trash-restore delete mode 100755 .local/libexec/cron/trash-prune diff --git a/.local/bin/trash-put b/.local/bin/trash-put deleted file mode 100755 index 82f4f5b16..000000000 --- a/.local/bin/trash-put +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/perl -use strict; -use warnings; -use feature("signatures"); - -use File::Path("make_path"); -use List::Util("max"); - -sub fs_root ($file_name) { - chomp( my $ret = `stat -c %m "$file_name"` ); - return $ret; -} - -sub file_info ($file) { - my $file_name = `basename "$file"`; - my $file_path = `realpath -s "$file"`; - chomp( $file_name, $file_path ); - my $file_fs_root = fs_root($file_name); - - return ( $file_name, $file_path, $file_fs_root ); -} - -sub trash_dirs ($file_fs_root) { - my $data_path = "$ENV{'XDG_DATA_HOME'}" // "$ENV{'HOME'}/.local/share"; - - my $trash_dir; - if ( $file_fs_root eq fs_root($data_path) ) { - $trash_dir = "$data_path/Trash/"; - } - else { - $trash_dir = "$file_fs_root/.Trash/"; - } - - return "${trash_dir}info", "${trash_dir}files"; -} - -sub target_file_name ( $file_name, $trash_file_path ) { - opendir( my $dir, "$trash_file_path" ) or die "$!"; - my $existing_suffix_nums = - map( ( $_ =~ /^${file_name}\.~(\d+)~/ ), readdir $dir ); - my $suffix_num = max($existing_suffix_nums) + 1; - my $suffix = "~" . $suffix_num . "~"; - closedir($dir); - - return "${file_name}.${suffix}"; -} - -sub write_file ( $file_path, $contents ) { - open( FH, '>', $file_path ) or die "$!"; - print FH $contents; -} - -# NOTE: Execution starts here - -if ( $#ARGV + 1 != 1 ) { - die "Bad Arguments"; -} - -stat $ARGV[0] or die "$!"; -my ( $file_name, $file_src, $file_fs_root ) = file_info( $ARGV[0] ); - -my ( $trash_info_path, $trash_file_path ) = trash_dirs($file_fs_root); -make_path( $trash_info_path, $trash_file_path ); - -my $target_name = target_file_name( $file_name, $trash_file_path ); -chomp( my $deletion_time = `date -u +%Y%m%dUTC%T` ); - -my $info_contents = < eq "[Trash Info]\n" or next; - my ( $name, $path, $suffix ) = - fileparse( ( =~ /(?<=Path=)(.+)$/ )[0] ); - $path =~ /^$search_path\/?$/ or next; - my $deletion_date = ( =~ /(?<=DeletionDate=)(.+)$/ )[0]; - chomp( $deletion_date = `date -d ${deletion_date} +'%x %X'` ); - push( @ret, [ $path, "${name}${suffix}", $deletion_date, $_ ] ); - } - return @ret; -} - -sub fzf_files (@files) { - my $n = 0; - my $str = ""; - for my $e (@files) { - $str = "$n | $$e[2] | $$e[1]\n" . $str; - $n++; - } - chomp($str); - my $sel = `echo '$str' | fzf`; - !$sel and exit; - my $index = substr( $sel, 0, index( $sel, ' ' ) ); - return $index; -} - -# NOTE: Execution starts here -# -my $target_directory; -if ( $#ARGV + 1 > 1 ) { - die "Bad Arguments\n"; -} -elsif ( $#ARGV + 1 == 1 ) { - $target_directory = shift; - chomp( $target_directory = `realpath -s $target_directory` ); - stat $target_directory or die "$!\n"; -} -else { - $target_directory = getcwd(); -} - -my $trash_dir = trash_dir( fs_root($target_directory) ); -my @files = trashed_files( $target_directory, $trash_dir ); -!@files and exit; -my $index = fzf_files(@files); - -my $file_dest = $files[$index][0] . $files[$index][1]; -my $file_src = $trash_dir . "files/" . $files[$index][3]; -my $file_info = $trash_dir . "info/" . $files[$index][3]; - -rename( $file_src, $file_dest ) or die "$!\n"; -unlink($file_info); diff --git a/.local/libexec/cron/trash-prune b/.local/libexec/cron/trash-prune deleted file mode 100755 index 924b9d9bf..000000000 --- a/.local/libexec/cron/trash-prune +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -IFS=' -' - -days=${1:-7} -types=${2:-ext2,ext3,ext4,xfs,btrfs,vfat,nfs} - -getfsroot() { - printf "%s" "$(df "$1" --output=target | tail -1)" -} - -list_trash_dirs() { - for mnt in $(findmnt -Py -t "$types"); do - eval "$mnt" - # shellcheck disable=2153 - if [ "$TARGET" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ]; then - target=${XDG_DATA_HOME:-$HOME/.local/share}/Trash - elif [ "$TARGET" = "/" ]; then - target=/.Trash - else - target=${TARGET}/.Trash - fi - [ -w "$target" ] && { echo "$target"; return; } - echo - done -} - -prune() { - [ -w "$1" ] || return 1 - for file in "$1"/files/*; do - file=$(basename "$file") - [ "$file" = '*' ] && return - if [ ! -r "$1/info/$file" ] || [ ! "$(head -1 "$1/info/$file")" = "[Trash Info]" ]; then - [ -w "$1/info/$file" ] && rm -rf "$1/info/$file" - rm -rf "$1/files/$file" - continue - fi - if [ "$(date -ud "$days days ago" +%s)" -gt "$(date -ud "$(grep DeletionDate "$1/info/$file" | cut -d '=' -f2)" +%s)" ]; then - echo "$file too old!" - rm -rf "$1/info/$file" - rm -rf "$1/files/$file" - fi - done -} - -for dir in $(list_trash_dirs); do - prune "$dir" || echo "Failed to prune $dir" -done