-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_tools_makeit
executable file
·75 lines (62 loc) · 1.55 KB
/
s_tools_makeit
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
#!/usr/bin/env bash
#
# Bin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Bin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Bin. If not, see <https://www.gnu.org/licenses/>.
#
# DEBUG OPTIONS
set -euo pipefail
# Description: make folders pointed by command followed by file
# Example: make_it.sh foo/bar/meh.sh bar/foo/file.py
# Shells supported: GNU Bash
# Inspiration: https://github.com/tanrax/terminal-AdvancedNewFile
# * VARS
ARGUMENTS=("$@")
PATH="${ARGUMENTS[0]}"
[[ "$#" -gt 1 ]] && VERBOSE="${ARGUMENTS[1]}"
# * FUNCTIONS
get_last_char() {
echo "${PATH: -1}"
}
is_dir() {
[[ $(get_last_char) == "/" ]]
}
get_filename() {
echo "${PATH##*/}"
}
get_dir_path() {
local result
result=$(is_dir && echo "$PATH" || echo ${PATH%$(get_filename)})
echo "$result"
}
create_dirs() {
mkdir -p "$(get_dir_path)"
}
create_file() {
echo '' >"$PATH"
}
run_verbose() {
if [[ "$VERBOSE" == "--verbose" ]]; then
echo <<EOF
Path --> $PATH
Directory --> $(get_dir_path)
Filename --> $(get_filename)
EOF
fi
}
run() {
run_verbose
create_dirs
create_file
}
# * MAIN
run