-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpst
executable file
·63 lines (54 loc) · 1.31 KB
/
pst
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
#!/bin/sh
usage() {
cat - <<EOF
Usage: pst [-n|--dry-run|--abort] [<target>]
-n|--dry-run: List file operations but don't execute.
--abort: List file operations and abort them all.
EOF
}
LST=~/.cp-mv-paste
TARGET="$PWD"
TARGET_SET=
DRY_RUN=
list() {
if [ -f "$LST/pending-cp" ]; then
xargs -0 -a "$LST/pending-cp" -n 1 -r -I '{}' printf 'cp -R %q %q\n' '{}' "$TARGET"
fi
if [ -f "$LST/pending-mv" ]; then
xargs -0 -a "$LST/pending-mv" -n 1 -r -I '{}' printf 'mv %q %q\n' '{}' "$TARGET"
fi
}
while [ "$#" -gt 0 ]; do
case "$1" in
-n | --dry-run)
DRY_RUN="YES"
;;
--abort)
list
rm -f "$LST/pending-cp"
rm -f "$LST/pending-mv"
;;
*)
if [ -z "$TARGET_SET" ]; then
TARGET="$(realpath "$1")"
TARGET_SET="YES"
else
usage
exit 1
fi
;;
esac
shift
done
list
if [ ! -z "$DRY_RUN" ]; then
exit 0
fi
if [ -f "$LST/pending-cp" ]; then
xargs -0 -a "$LST/pending-cp" -n 1 -r -I '{}' cp -R '{}' "$TARGET"
rm -f "$LST/pending-cp"
fi
if [ -f "$LST/pending-mv" ]; then
xargs -0 -a "$LST/pending-mv" -n 1 -r -I '{}' mv '{}' "$TARGET"
rm -f "$LST/pending-mv"
fi