bin: initial sortit commit

This commit is contained in:
2020-06-23 13:46:00 +01:00
parent 6e437a7851
commit 54762ffa7a

42
bin/sortit.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
function getsourcefiles() {
local src=$1
unset i
while IFS= read -r -u3 -d $'\0' file; do
files[i++]="$file"
done 3< <(ls "$src" | fzf -m --print0)
if [ "$i" == "" ] ; then
echo "You didn't choose any files."
exit 1
fi
}
function getdestdir() {
dir=$(ls "$1" | fzf)
if [ "$dir" == "" ] ; then
echo "No destination selected."
exit 1
fi
}
if [ $# -lt 2 ] ; then
echo $0 src_dir dest_parent
exit 1
fi
src_dir=$1
dest_dir=$2
while [ 1 == 1 ] ; do
getsourcefiles $src_dir
getdestdir $dest_dir
destpath=$(realpath "$2/$dir")
for i in "${files[@]}"
do
# echo mv -i "$1/${i}" "$destpath"
mv -i "$1/${i}" "$destpath"
done
done