diff --git a/.config/lf/lfrc b/.config/lf/lfrc index facc56d4..6ebca516 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -72,12 +72,17 @@ cmd delete ${{ }} cmd trash ${{ - clear; tput cup $(($(tput lines)/3)); tput bold - set -f - printf "%s\n\t" "$fx" - printf "trash?[y/N]" - read ans - [ $ans = "y" ] && trash-put $fx + clear; tput cup $(($(tput lines)/3)); tput bold + set -f + printf "%s\n\t" "$fx" + printf "trash?[y/N]" + read ans + if [ $ans = "y" ]; then + for f in $fx; do + echo $f + trash-put $f + done + fi }} cmd rsyncto ${{ @@ -143,6 +148,16 @@ cmd paste &{{ lf -remote "send clear" }} +cmd dupe &{{ + for file in $fx; do + find "$PWD" "$file" | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | ( + ext=$(($(cat /dev/stdin)+1)) + filedest="$(echo "$file" | sed 's/.~[[:digit:]]*~$//').~$ext~" + cp "$file" "$filedest" + ) + done +}} + cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c # Bindings @@ -153,6 +168,7 @@ map d $lf -remote "send $id cd '$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/ map J $dir=$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf) && lf -remote "send $id cd $(eval echo $dir)" map D trash map delete +map T $trash-restore $PWD map E extract map R rsyncto map P link @@ -174,7 +190,7 @@ map I push A # after extension map i push A # before extension map c push A # new rename map B bulkrename -map b $cp "$f" "$f-COPY" +map b dupe map u :clear; unselect map n &echo $f | xclip -r -selection c map N diff --git a/.local/bin/trash-put b/.local/bin/trash-put new file mode 100755 index 00000000..5bce53be --- /dev/null +++ b/.local/bin/trash-put @@ -0,0 +1,28 @@ +#!/bin/sh +set -e +[ -e "$1" ] || exit 1 +getfsroot() { + printf "%s" "$(df "$1" --output=target | tail -1)" +} + +filepath="$(realpath "$1")" +filename="$(basename "$1")" +fsroot="$(getfsroot "$1")" +[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] \ + && basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" \ + || basedir="${fsroot}/.Trash" +infodir="$basedir/info" +filedir="$basedir/files" + +mkdir -p "$infodir" 1>/dev/null 2>&1 +mkdir -p "$filedir" 1>/dev/null 2>&1 +find "$filedir" -regex ".*$filename.*" | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | ( +ext=$(($(cat /dev/stdin)+1)) +filedest="$filedir/$filename.~$ext~" +command mv -f "$filepath" "$filedest" +cat < "$infodir/$(basename "$filedest")" +[Trash Info] +Path=$filepath +DeletionDate=$(date +%Y%m%dT%T) +EOF +) diff --git a/.local/bin/trash-restore b/.local/bin/trash-restore new file mode 100755 index 00000000..b850c40e --- /dev/null +++ b/.local/bin/trash-restore @@ -0,0 +1,31 @@ +#!/bin/sh +set -e +getfsroot() { + printf "%s" "$(df "$1" --output=target | tail -1)" +} +list() { + # 1st arg is trash files directory + # 2nd arg is directory to match trash files for + [ ! "$(ls -A "$1")" ] && exit 1 + for file in "$1"/* ; do + [ "$(head -1 "$file")" = "[Trash Info]" ] && \ + fpath=$(grep Path "$file" | cut -d '=' -f2) && \ + echo "$fpath" | grep -qP "^$2/[^/]+$" && \ + printf "%s %s %s\n" \ + "$(basename "$file")" \ + "$fpath" \ + "$(date -d "$(grep Date "$file" | cut -d '=' -f2)" +'%x %X')" + done +} + +[ -n "$1" ] && dir="$(realpath "$1")" || dir="$(getfsroot "$PWD")" +fsroot="$(getfsroot "$dir")" +[ "$fsroot" = "$(getfsroot "${XDG_DATA_HOME:-$HOME/.local/share}")" ] \ + && basedir="${XDG_DATA_HOME:-$HOME/.local/share}/Trash" \ + || basedir="${fsroot}/.Trash" + +sel="$(list "$basedir/info" "$dir" | fzf)" +file="$basedir/files/$(echo "$sel" | cut -d ' ' -f1)" +dest="$(echo "$sel" | cut -d ' ' -f2)" +command mv -ib "$file" "$dest" +command rm "$basedir/info/$(echo "$sel" | cut -d ' ' -f1)"