sorter.sh: improvements
- added L option for preserving information - don't review files in the trash
This commit is contained in:
parent
b5e18021e8
commit
9bb52d016d
@ -6,38 +6,57 @@ view() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirsel() {
|
dirsel() {
|
||||||
FILEPATH=$(
|
find ~/med/memes/ ~/med/rw/ -type d | \
|
||||||
find ~/med/memes/ ~/med/rw/ -type d |
|
fzf --filepath-word --query "$1" --header "Select directory" | \
|
||||||
fzf --no-sort --query "$1" --header "Select directory" | \
|
sed 's:/*$::'
|
||||||
(
|
|
||||||
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:/*$::'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namesel() {
|
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
|
while read -r FILE; do
|
||||||
|
clear
|
||||||
view "$FILE"
|
view "$FILE"
|
||||||
EXT="${FILE##*.}"
|
EXT="${FILE##*.}"
|
||||||
DIR="$(dirsel "")"
|
DIR="$(dirsel "$PREVDIR")"
|
||||||
NAME="$(namesel "$DIR" "")"
|
NAME="$(namesel "$DIR" "$PREVNAME")"
|
||||||
|
PREVDIR=""
|
||||||
|
PREVNAME=""
|
||||||
while true; do
|
while true; do
|
||||||
clear
|
printf "\n\n%s\n" "$FILE"
|
||||||
printf "%s\n" "$FILE"
|
|
||||||
DESTPATH="$DIR"/"$NAME"."$EXT"
|
DESTPATH="$DIR"/"$NAME"."$EXT"
|
||||||
printf "send to: %s\n" "$DESTPATH"
|
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> "
|
printf "\n> "
|
||||||
read -n 1 ANS < /dev/tty
|
read -n 1 ANS < /dev/tty
|
||||||
case "$ANS" in
|
case "$ANS" in
|
||||||
@ -45,14 +64,12 @@ while read -r FILE; do
|
|||||||
h ) view "$FILE";;
|
h ) view "$FILE";;
|
||||||
j ) DIR="$(dirsel "$DIR")";;
|
j ) DIR="$(dirsel "$DIR")";;
|
||||||
k ) NAME="$(namesel "$DIR" "$NAME")";;
|
k ) NAME="$(namesel "$DIR" "$NAME")";;
|
||||||
l )
|
l ) confirm "$DESTPATH" "$FILE" && break;;
|
||||||
if [ -e "$DESTPATH" ]; then
|
L ) if confirm "$DESTPATH" "$FILE"; then
|
||||||
printf "'%s' already exists.\n" "$DESTPATH"
|
PREVDIR="$DIR"
|
||||||
else
|
PREVNAME="$NAME"
|
||||||
mv -n "$FILE" "$DESTPATH"
|
break
|
||||||
break
|
fi;;
|
||||||
fi
|
|
||||||
;;
|
|
||||||
s ) break;;
|
s ) break;;
|
||||||
d ) mv "$FILE" ~/quar/trash/; break;;
|
d ) mv "$FILE" ~/quar/trash/; break;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user