-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-fdupes.sh
executable file
·62 lines (59 loc) · 1.39 KB
/
process-fdupes.sh
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
#!/bin/sh
delete='rm -f $verbose_opt "$next"'
link='ln -f $verbose_opt "$last" "$next"'
message=false
verbose_opt=-v
cmd="$link"
header=false
die () { echo "$@" >&2; exit 2; }
ask () {
local reply
read -n 1 -p "$1 [y|N]" reply
[ "$reply" = y -o "$reply" = Y ]
}
while getopts ahnvqldc: FLAG; do
case $FLAG in
a) ask=true;;
h) die \
'Pipe the ouput of fdupes into this script.
Valid options are
-l to link or
-d to delete duplicates,
-v and -q for verbose or quiet mode,
-a to ask before running the command,
-n for test runs (noop) and
-H to skip first line of each duplicates block (header lines).';;
H) header=true;;
n) noop=true;;
v) message=echo verbose_opt=-v;;
q) message=false verbose_opt=;;
l) cmd="$link";;
d) cmd="$delete";;
c) cmd="$OPTARG";;
*) die Try $0 -h;;
esac
done
if [ -t 0 ]; then
die You have to pipe the ouput of fdupes into this script.
fi
if [ "$noop" ]; then cmd="echo $cmd"
#elif [ "$ask" ]; then cmd="ask 'Run $cmd ?' && $cmd"
fi
next=
last=
while read next; do
if [ "$last" = '' ]; then
$message \$last was empty when reading \$next, continueing... >&2
last="$next"
elif [ "$next" = '' ]; then
$message Read empty line, reseting \$last ... >&2
last=
if $header; then
$message Reading \(and dropping\) header line ... >&2
read next
fi
else
eval $cmd
last="$next"
fi
done