aboutsummaryrefslogtreecommitdiff
path: root/local/bin/junk
blob: faf9b32852d8c89005fd0da3d8698b7176368d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

set -e

junk_dir="$HOME/data/junk"
[ ! -d "$junk_dir" ] && mkdir "$junk_dir"

for arg in "$@"
do
    dest="$junk_dir/$arg"
    if [ -e "$dest" ]
    then
        echo "$dest already exists, generating a prefix"
        identifier="$(seq 100 | xargs -I N sh -c "echo N; test -e '$dest__N' || exit 255" 2> /dev/null | tail -n1)"
        dest="$dest"__"$identifier"
    fi
    mv "$arg" "$dest" &&
        echo "$arg moved to $dest" || true
done