-
Notifications
You must be signed in to change notification settings - Fork 0
/
obl
executable file
·35 lines (32 loc) · 1.18 KB
/
obl
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
#!/usr/bin/env bash
if [[ ($# -ne 1) && ($# -ne 2) ]]
then
echo "usage is $0 <file or directory to sent to the oblivion directory> (<optional suffix to use>) "
exit 1;
else
if [ -z ${CACHE_OF_OBLIVION+x} ]; then # http://stackoverflow.com/a/13864829/274677
printf "\n\n\n\n\n\t\tCACHE_OF_OBLIVION is unset, cowardly refusing to proceed\n\n\n";
exit 2;
fi
mkdir -p "${CACHE_OF_OBLIVION}"
THING_TO_MOVE_TO_OBLIVION=$1
if [ ! -e ${THING_TO_MOVE_TO_OBLIVION} ]; then
echo "File or directory ${THING_TO_MOVE_TO_OBLIVION} not found!"
exit 3;
fi
SUFFIX=$2
if [[ -z "${SUFFIX}" ]]
then
THING_TO_MOVE_TO_OBLIVION_TIP=$(basename $THING_TO_MOVE_TO_OBLIVION)
else
THING_TO_MOVE_TO_OBLIVION_TIP=$(basename $THING_TO_MOVE_TO_OBLIVION).${SUFFIX}
fi
readonly TIMESTAMP=$( date '+%Y-%m-%d_%0H%0M%0S' )
readonly DEST=$CACHE_OF_OBLIVION/$THING_TO_MOVE_TO_OBLIVION_TIP-$TIMESTAMP
if [ -e ${DEST} ]; then
printf "${DEST} strangely exists, cowardly refusing to proceed"
exit 4;
fi
mv $THING_TO_MOVE_TO_OBLIVION $DEST
printf "Moved $THING_TO_MOVE_TO_OBLIVION to $DEST\n"
fi