-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortto
More file actions
executable file
·69 lines (61 loc) · 1020 Bytes
/
Copy pathsortto
File metadata and controls
executable file
·69 lines (61 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
err() {
echo "$(color red)$@$(color off)" >&2
}
warn() {
echo "$(color ltblue)$@$(color off)" >&2
}
die() {
err $@
exit 1
}
die() {
warn "sortto [files]"
}
# m/i/m returns media/images/memes
find_sort_location() {
find "$BASE" -type d -wholename "$BASE/$(echo $1 | sed -E 's|([^/]+)|\1*|g')" | head -1
}
movemcd() {
mv --debug --no-clobber $MV_ARGS "$1" "$2"
}
_sortto() {
movemcd "$1" "$SORT_LOCATION"
}
BASE="$HOME/media"
SORT_LOCATION="$BASE/images"
while [ $# -gt 0 ]; do
case "$1" in
--quiet)
warn(){ :; }
shift
;;
--dry)
movemcd(){ :; }
shift
;;
--force)
MV_ARGS="$MV_ARGS --force"
shift
;;
--base)
shift
set -u; BASE=$1; set +u
shift
;;
-*)
if CANDIDATE="$(find_sort_location ${1#?})"
then SORT_LOCATION="$CANDIDATE"
else "warn could not find value valid location for ${1#?} in $BASE"
fi
shift
;;
*)
_sortto "$1"
shift
;;
esac
done
if read -t 0; then while read line; do
_sortto "$line"
done fi