forked from xcv58/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution
executable file
·45 lines (35 loc) · 823 Bytes
/
solution
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
#!/bin/bash
set -e
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
ext="java"
function show_help() {
echo "$(basename "$0") [-l] [-l java] The Problem Name
It will
1. Create directory of 'The-Problem-Name'
2. Use default EDITOR to open 'The-Problem-Name/Solution.java' file
where:
-h show this help text
-l set the language (default: java)"
}
while getopts "h?l:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
l) ext=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
function join { local IFS="$1"; shift; echo "$*"; }
directory=$(join "-" "${@}")
if [ -z "${directory}" ]; then
show_help
exit 1
fi
mkdir "${directory}"
${EDITOR} "${directory}/Solution.${ext}"