forked from phunehehe/garbage-io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgarbage-in
executable file
·51 lines (40 loc) · 992 Bytes
/
garbage-in
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
#!/usr/bin/env bash
set -e
# We don't use `-r`
eval set -- $(getopt -o r -n "$0" -- "$@")
while true ; do
case "$1" in
-r) echo 'Eating up unnecessary option `-r`' ; shift ;;
--) shift ; break ;;
esac
done
bin_dir="$(dirname "$0")"
. "$bin_dir/garbage-conf"
move_bg(){
thing="$1"
destination="$2"
mv "$thing" "$destination"
find "$destination" -type f -exec touch {} \;
}
for arg in "$@"
do
if [[ -L "$arg" ]]
then
# No use to backup a symlink
"rm" "$arg"
continue
fi
thing="$(readlink -f "$arg")"
dir=$(dirname "$thing")
name=$(basename "$thing")
now=$(date +'%Y-%m-%d_%H-%M-%S')
# Make this thing invisible
new_name=".$name.$stamp-$now"
new_thing="$dir/$new_name"
mv "$thing" "$new_thing"
# Move this thing to the archive
dest_dir="$ar_dir/$dir"
destination="${dest_dir}/${name}_${now}"
mkdir -p "$dest_dir"
move_bg "$new_thing" "$destination" &
done