aboutsummaryrefslogtreecommitdiff
path: root/local/bin/junk
blob: 9758f68df7245164c94fcbf97ea5f934ee8a4033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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
    if mv "$arg" "$dest"
    then
        echo "$arg moved to $dest"
    fi
done