sorter.sh: improvements

- added L option for preserving information
- don't review files in the trash
This commit is contained in:
dogeystamp 2023-03-04 11:57:06 -05:00
parent b5e18021e8
commit 9bb52d016d
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38

View File

@ -6,38 +6,57 @@ view() {
}
dirsel() {
FILEPATH=$(
find ~/med/memes/ ~/med/rw/ -type d |
fzf --no-sort --query "$1" --header "Select directory" | \
(
read -r QUERY
read -r RES
if [ -z "$(printf "%s" "$RES" | tr -d '\n')" ]; then
printf "%s" "$QUERY"
else
printf "%s" "$RES"
fi
)
)
printf "%s" "$FILEPATH" | sed 's:/*$::'
find ~/med/memes/ ~/med/rw/ -type d | \
fzf --filepath-word --query "$1" --header "Select directory" | \
sed 's:/*$::'
}
namesel() {
ls "$1" | fzf --print-query --query "$2" --header "Select filename"
if [ -z "$1" ]; then
return 1
fi
ls "$1" | fzf -x --filepath-word --print-query --query "$2" --header "Select filename" | head -n 1
}
find ~/quar -name '*.mov' -or -name '*.MOV' -or -name '*.mp4' -or -name '*.jpg' -or -name '*.png' -or -name '*.jpeg' | \
confirm() {
DESTPATH="$1"
FILE="$2"
if [ -e "$DESTPATH" ]; then
printf "'%s' already exists.\n" "$DESTPATH"
return 1
else
mv -n "$FILE" "$DESTPATH"
return 0
fi
}
PREVDIR=""
PREVNAME=""
find ~/quar \
-type f \
-not -path '*/trash/*' \
\( \
-name '*.mov' -o \
-name '*.MOV' -o \
-name '*.mp4' -o \
-name '*.jpg' -o \
-name '*.png' -o \
-name '*.jpeg' -o \
-name '*.gif' \
\) | \
while read -r FILE; do
clear
view "$FILE"
EXT="${FILE##*.}"
DIR="$(dirsel "")"
NAME="$(namesel "$DIR" "")"
DIR="$(dirsel "$PREVDIR")"
NAME="$(namesel "$DIR" "$PREVNAME")"
PREVDIR=""
PREVNAME=""
while true; do
clear
printf "%s\n" "$FILE"
printf "\n\n%s\n" "$FILE"
DESTPATH="$DIR"/"$NAME"."$EXT"
printf "send to: %s\n" "$DESTPATH"
printf "\nh view again, j set directory, k set name, l confirm, q exit, s skip\nd move to trash\n"
printf "\nh view again, j set directory, k set name, l confirm, L confirm and preserve information\n q exit, s skip, d move to trash\n"
printf "\n> "
read -n 1 ANS < /dev/tty
case "$ANS" in
@ -45,14 +64,12 @@ while read -r FILE; do
h ) view "$FILE";;
j ) DIR="$(dirsel "$DIR")";;
k ) NAME="$(namesel "$DIR" "$NAME")";;
l )
if [ -e "$DESTPATH" ]; then
printf "'%s' already exists.\n" "$DESTPATH"
else
mv -n "$FILE" "$DESTPATH"
break
fi
;;
l ) confirm "$DESTPATH" "$FILE" && break;;
L ) if confirm "$DESTPATH" "$FILE"; then
PREVDIR="$DIR"
PREVNAME="$NAME"
break
fi;;
s ) break;;
d ) mv "$FILE" ~/quar/trash/; break;;
esac