Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 58 lines (44 sloc) 1.1 KB
#!/usr/bin/env bash
set -efuo pipefail
garbage_dir=$HOME/.garbage
# We don't use `-r`
eval set -- "$(getopt -o r -n "$0" -- "$@")"
while true ; do
case "$1" in
-r)
# shellcheck disable=SC2016
echo 'Eating up unnecessary option `-r`' ; shift ;;
--) shift ; break ;;
esac
done
bin_dir="$(dirname "$0")"
# shellcheck source=/dev/null
. "$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.GARBAGE-$now"
new_thing="$dir/$new_name"
mv "$thing" "$new_thing"
# Move this thing to the archive
dest_dir="$garbage_dir/$dir"
destination="${dest_dir}/${name}_${now}"
mkdir -p "$dest_dir"
move_bg "$new_thing" "$destination" &
done