-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpm.sh
executable file
·58 lines (52 loc) · 1.07 KB
/
cpm.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
#!/usr/bin/env sh
BUFFER=/tmp/cpm
copy() {
for p; do
p=$(realpath -- "$p")
if grep -qx "$p" $BUFFER; then
echo Already in buffer: "$p"
elif [ -f "$p" ] || [ -d "$p" ]; then
echo "$p" >> $BUFFER
else
echo Does\'t exist: "$p"
fi
done
}
paste() {
while read -r LINE; do
if [ -f "$LINE" ] || [ -d "$LINE" ]; then
cp -fr "$LINE" . && echo Pasted: "$LINE"
else
echo Doesn\'t exist: "$LINE"
fi
done < $BUFFER
}
move() {
while read -r LINE; do
if [ -f "$LINE" ] || [ -d "$LINE" ]; then
mv -f "$LINE" . && echo Moved: "$LINE"
else
echo Doesn\'t exist: "$LINE"
fi
done < $BUFFER
: > $BUFFER
}
[ ! -f $BUFFER ] && touch $BUFFER
case $@ in
"") cat $BUFFER ;;
-c\ *)
shift
copy "$@"
;;
-d) : > $BUFFER ;;
-p) paste ;;
-m) move ;;
-*)
echo Invalid arguments. >&2
exit 1
;;
*)
: > $BUFFER
copy "$@"
;;
esac