-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_solution_script.sh
More file actions
executable file
·47 lines (35 loc) · 1.19 KB
/
create_solution_script.sh
File metadata and controls
executable file
·47 lines (35 loc) · 1.19 KB
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
#! /bin/bash
usage="$(basename "$0") - Template for automatic creation of raw, blank scripts with given name and extension in provided directory - because who wants to type it by its own???!
-d <dir> [current_dir] - directory for new file to be saved at
-n <Any name> - name of a file in qoutes - any dots/lines will be removed and spaces replaces by underscores
-e <extension> [cpp] - extension of a future file
Enjoy!
"
EXTENSION="cpp"
OUTDIR="./"
if [ "$1" == "-h" ]; then
echo "$usage"
exit 0
fi
while getopts ":d:n:h:e:" opt; do
case $opt in
d)
OUTDIR=$OPTARG;;
n)
NAME="$OPTARG";;
e)
EXTENSION="$OPTARG";;
\?)
echo "Invalid parameter!"
exit;;
esac
done
NAME="${NAME// /_}" # replace spaces by underscores
NAME="${NAME//-/_}" # delete replace lines by underscores
NAME="${NAME//\`/}" # delete '`' from name
NAME="${NAME//\'/}" # delete ' from name
NAME="${NAME//./}.${EXTENSION}" # delete dots from name
mkdir -p $OUTDIR # create directory if it doesn`t exist
whole_name="${OUTDIR}/${NAME}"
touch $whole_name
echo "File with name ${NAME} was created at ${whole_name}"