-
Notifications
You must be signed in to change notification settings - Fork 11
/
mkdir-now
executable file
·68 lines (61 loc) · 1.92 KB
/
mkdir-now
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
help() {
echo "mkdir-now [--full] [--no-create] [--ignore-existing] [--script|-s] [--name TEXT]"
echo
echo " creates a directory named by the current date. F.ex."
echo
echo " $ mkdir-now"
echo ' Created "2010-01-22/"'
echo
echo " --script will only return name of created dir on stdout"
echo " -s same as --script"
echo " --no-create don't create dir, only return name of dir that would be"
echo " --ignore-existing do not error out if directory already exists"
echo " --full create directory with full date, such as"
echo " 2010-01-22_20:26/"
echo " --name TEXT will allow you to add so string to the name"
echo " of the created directory. F.ex."
echo
echo ' $ mkdir-now -name "researching segfault"'
echo ' Created "2010-01-22 researching segfault/"'
echo
exit -1
}
[ "$1" == "--help" ] && help
while [ "$1" != "" ]; do
case "$1" in
--full) FULL="true"; shift ;;
--no-create) NO_CREATE="true"; shift ;;
--ignore-existing) IGNORE_EXISTING="true"; shift ;;
--script) SCRIPT="true"; shift ;;
-s) SCRIPT="true"; shift ;;
--name) NAME="true"; shift; NAME_ADD="$1"; shift ;;
*) help ;;
esac
done
if [ "$FULL" == "true" ]; then
dir="`date +%F_%R`"
else
# default
dir="`date +%F`"
fi
if [ "$NAME" == "true" ]; then
dir="$dir $NAME_ADD"
fi
if [ "$NO_CREATE" == "true" ]; then
echo "$dir"
exit 0
elif [ -e "$dir" ]; then
if [ "$IGNORE_EXISTING" != "true" ]; then
echo "\"$dir\" already exists" >&2
exit -2
fi
else
# default
mkdir "$dir"
fi
if [ "$SCRIPT" == "true" ]; then
echo "$dir"
else
echo "Created \"$dir/\"" >&2
fi