1
1
#! /usr/bin/env bash
2
2
3
3
# Global constants
4
- PINE_VERSION=1.0 .0
4
+ PINE_VERSION=1.1 .0
5
5
FILE_NOT_FOUND_EX=2
6
6
LOG_FILE=/tmp/pine_logs/log.txt
7
- SRC_PATH= " "
8
- SCRIPT_PATH= " "
7
+ SCRIPTPATH= " $( cd " $( dirname " $0 " ) " ; pwd -P ) "
8
+ SRC_PATH= " $PWD "
9
9
GITIGNORE_REPO=" https://github.com/github/gitignore.git"
10
- # Global variables
11
- declare -A map # map for easy searching of names
12
10
11
+ # Import functions
12
+ source " ${SCRIPTPATH} /paramparser.sh" # For parameter parsing
13
+ source " ${SCRIPTPATH} /inc/error.sh" # For error handling
14
+ source " ${SCRIPTPATH} /custpathhandler.sh" # For handling custom dir
13
15
14
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
15
- # From: https://stackoverflow.com/a/38153758/6556360
16
- # parse the arguments.
17
- parse_params ()
18
- {
19
- local existing_named
20
- local ARGV=()
21
- echo " local ARGV=(); "
22
- while [[ " $1 " != " " ]]; do
23
- # If equals delimited named parameter
24
- if [[ " $1 " =~ ^..* = ..* ]]; then
25
- # key is part before first =
26
- local _key=$( echo " $1 " | cut -d = -f 1)
27
- # val is everything after key and = (protect from param==value error)
28
- local _val=" ${1/ $_key =} "
29
- # remove dashes from key name
30
- _key=${_key// \- }
31
- # search for existing parameter name
32
- if (echo " $existing_named " | grep " \b$_key \b" > /dev/null); then
33
- # if name already exists then it's a multi-value named parameter
34
- # re-declare it as an array if needed
35
- if ! (declare -p _key 2> /dev/null | grep -q ' declare \-a' ); then
36
- echo " $_key =(\"\$ $_key \" );"
37
- fi
38
- # append new value
39
- echo " $_key +=('$_val ');"
40
- else
41
- # single-value named parameter
42
- echo " local $_key =\" $_val \" ;"
43
- existing_named=" $_key "
44
- fi
45
- # If standalone named parameter
46
- elif [[ " $1 " =~ ^\- . ]]; then
47
- # remove dashes
48
- local _key=${1// \- }
49
- echo " local $_key =\" $_key \" ;"
50
- # non-named parameter
51
- else
52
- # escape asterisk to prevent bash asterisk expansion
53
- _escaped=${1/ \* / \'\" * \"\' }
54
- echo " ARGV+=('$_escaped ');"
55
- fi
56
- shift
57
- done
58
- }
59
- # -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
16
+ # Global variables
17
+ declare -A map # map for easy searching of names
18
+ declare -A dirNameMap # map for easy searching of names
60
19
61
20
# Updates all gitignore files in ${SCRIPTPATH}/gitignore
62
21
function update_config_files() {
@@ -167,6 +126,7 @@ function add_config_to_file() {
167
126
echo " ERROR: Configuration exists, skipping"
168
127
} || {
169
128
echo " Adding configuration for $arg "
129
+ echo " " >> ${SRC_PATH} /.gitignore
170
130
echo -e " #### ${1} ##########################" >> ${SRC_PATH} /.gitignore
171
131
echo -e " #### DO NOT DELETE PRECEDING LINE" >> ${SRC_PATH} /.gitignore
172
132
echo -e " #### PINE" >> ${SRC_PATH} /.gitignore
@@ -195,11 +155,10 @@ function remove_config_from_file() {
195
155
echo " $currentcontent " | awk -v a=" $1 " -f ${SCRIPTPATH} /utilities/remove.awk > ${SRC_PATH} /.gitignore
196
156
}
197
157
158
+
198
159
function init() {
199
160
set -e
200
- SCRIPTPATH=" $( cd " $( dirname " $0 " ) " ; pwd -P ) "
201
- SRC_PATH=" $PWD "
202
-
161
+
203
162
# Checks the presence of config files
204
163
check_and_update_config_files
205
164
@@ -214,9 +173,6 @@ function init() {
214
173
mkdir -p /tmp/pine_logs
215
174
fi
216
175
217
- # Load error.sh or display error and exit
218
- source " ${SCRIPTPATH} /inc/error.sh"
219
-
220
176
load_names
221
177
eval $( parse_params " $@ " ) # Parse parameters
222
178
@@ -246,8 +202,6 @@ function init() {
246
202
list_all_config
247
203
exit
248
204
fi
249
-
250
-
251
205
252
206
# Search each parameter
253
207
for arg in " ${ARGV[@]} " ; do
0 commit comments