-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate
executable file
·76 lines (68 loc) · 1.53 KB
/
create
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
69
70
71
72
73
74
75
76
#!/bin/bash -e
help_echo () {
echo
echo "Usage: ./create"
echo -e "\t -c|--command - Set flag when to create new git command"
echo -e "\t -s|--script - Set flag when to create new git script"
echo -e "\t -f|--file - Flag defines the name of the file to create"
}
POSITIONAL_ARGS=()
COMMAND="1"
SCRIPT="1"
while [[ $# -gt 0 ]]; do
case $1 in
-c|--command)
COMMAND="0"
shift # past argument
;;
-s|--script)
SCRIPT="0"
shift # past argument
;;
-f|--file)
FILENAME="$2"
shift # past argument
shift # past value
;;
-h|--help)
help_echo
exit 0
;;
-*|--*)
echo "Unknown option $1"
help_echo
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [[ -z "$FILENAME" ]]; then
echo "Must provide file option."
help_echo
exit 1
fi
create_file () {
local path=$1
local file_name=$2
local file_path="$path/$file_name"
local type=$3
if [ -f "$file_path" ]; then
echo "WARNING: [$file_name] file name exists as part of [$type]. Try a different name"
return
fi
echo "#!/bin/bash -e" > $file_path
chmod u+x $file_path
echo "Created File: $file_path"
}
if [ $SCRIPT = "0" ]; then
sript_path="$(pwd)/scripts"
create_file $sript_path $FILENAME 'script'
fi
if [ $COMMAND = "0" ]; then
command_path="$(pwd)/commands"
create_file $command_path $FILENAME 'command'
fi