Skip to content

Commit 058f5d1

Browse files
authored
Merge pull request #3 from suyashmahar/version/1.1
🎉 Version 1.1
2 parents 728ef39 + 8a2f787 commit 058f5d1

File tree

6 files changed

+150
-67
lines changed

6 files changed

+150
-67
lines changed

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Gitignore configurations for emacs
2+
# -*- mode: gitignore; -*-
3+
*~
4+
\#*\#
5+
/.emacs.desktop
6+
/.emacs.desktop.lock
7+
*.elc
8+
auto-save-list
9+
tramp
10+
.\#*
11+
12+
# Org-mode
13+
.org-id-locations
14+
*_archive
15+
16+
# flymake-mode
17+
*_flymake.*
18+
19+
# eshell files
20+
/eshell/history
21+
/eshell/lastdir
22+
23+
# elpa packages
24+
/elpa/
25+
26+
# reftex files
27+
*.rel
28+
29+
# AUCTeX auto folder
30+
/auto/
31+
32+
# cask packages
33+
.cask/
34+
dist/
35+
36+
# Flycheck
37+
flycheck_*.el
38+
39+
# server auth directory
40+
/server/
41+
42+
# projectiles files
43+
.projectile
44+
45+
# directory configuration
46+
.dir-locals.el

HELP.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Options:
88
-r --remove Remove configuration for all config files specified from
99
.gitignore file in current directory.
1010

11-
-u --update Update local configuration files and exit.
11+
-u --update Update local configuration files and exit.
12+
13+
--list List all configuration files present in current directory's
14+
.gitignore file
1215

1316
-v --version Print current version number and exit.
1417

@@ -18,11 +21,14 @@ Examples
1821
========
1922

2023
To add configuration for java, c:
21-
pine c java
24+
pine c java
25+
26+
To remove configuration for java:
27+
pine -r java
2228

23-
To remove configuration for java
24-
pine -r java
29+
To list all configurations present in current directory's .gitignore file:
30+
pine --list
2531

26-
To update
27-
pine --update
32+
To update:
33+
pine --update
2834

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Run the following command in your terminal to download and install pine.
1111

1212
If you are using bash:
1313
```shell
14-
git clone https://github.com/suyashmahar/pine.git $HOME/pine && echo 'export PATH="$HOME/pine:$PATH"' >> $HOME/.bashrc && source $HOME/.bashrc
14+
git clone https://github.com/suyashmahar/pine.git "$HOME/pine" && echo 'export PATH="$HOME/pine:$PATH"' >> "$HOME/.bashrc" && source "$HOME/.bashrc"
1515
```
1616

1717
If you are using zsh:
1818
```shell
19-
git clone https://github.com/suyashmahar/pine.git $HOME/pine && echo 'export PATH="$HOME/pine:$PATH"' >> $HOME/.zshrc && source $HOME/.zshrc
19+
git clone https://github.com/suyashmahar/pine.git "$HOME/pine" && echo 'export PATH="$HOME/pine:$PATH"' >> "$HOME/.zshrc" && source "$HOME/.zshrc"
2020
```
2121

2222
Usage

custpathhandler.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /usr/bin/env bash
2+
3+
# Contains functions for handling all custom .gitignore
4+
# directory related features
5+
6+
function load_dirs() {
7+
if [ -f "${SCRIPTPATH}/dirs.list" ]; then
8+
dirNames=`cat ${SCRIPTPATH}/dirs.list`
9+
else
10+
echo "WARNING: Directory list not compiled"
11+
echo "INFO: Adding default default gitignore directories."
12+
13+
# Add 2 default locations present in github's repository
14+
echo ":${SCRIPTPATH}/gitignore" >> "${SCRIPTPATH}/dirs.list"
15+
if [ -d "${SCRIPTPATH}/global" ]; then
16+
echo "global:${SCRIPTPATH}/global" >> "${SCRIPTPATH}/dirs.list"
17+
fi
18+
19+
load_dirs
20+
return
21+
fi
22+
23+
# Read each line from dirs.list and add an entry to map.
24+
# Lines in dirs.list have pattern:
25+
# alias:path
26+
while read -r line; do
27+
lineSplit=("$line")
28+
dirNameMap["${lineSplit[0]}"]="${lineSplit[1]}"
29+
done < "${SCRIPTPATH}/dirs.list"
30+
31+
}

paramparser.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env bash
2+
3+
# From: https://stackoverflow.com/a/38153758/6556360
4+
# parse the arguments.
5+
parse_params ()
6+
{
7+
local existing_named
8+
local ARGV=()
9+
echo "local ARGV=(); "
10+
while [[ "$1" != "" ]]; do
11+
# If equals delimited named parameter
12+
if [[ "$1" =~ ^..*=..* ]]; then
13+
# key is part before first =
14+
local _key=$(echo "$1" | cut -d = -f 1)
15+
# val is everything after key and = (protect from param==value error)
16+
local _val="${1/$_key=}"
17+
# remove dashes from key name
18+
_key=${_key//\-}
19+
# search for existing parameter name
20+
if (echo "$existing_named" | grep "\b$_key\b" >/dev/null); then
21+
# if name already exists then it's a multi-value named parameter
22+
# re-declare it as an array if needed
23+
if ! (declare -p _key 2> /dev/null | grep -q 'declare \-a'); then
24+
echo "$_key=(\"\$$_key\");"
25+
fi
26+
# append new value
27+
echo "$_key+=('$_val');"
28+
else
29+
# single-value named parameter
30+
echo "local $_key=\"$_val\";"
31+
existing_named=" $_key"
32+
fi
33+
# If standalone named parameter
34+
elif [[ "$1" =~ ^\-. ]]; then
35+
# remove dashes
36+
local _key=${1//\-}
37+
echo "local $_key=\"$_key\";"
38+
# non-named parameter
39+
else
40+
# escape asterisk to prevent bash asterisk expansion
41+
_escaped=${1/\*/\'\"*\"\'}
42+
echo "ARGV+=('$_escaped');"
43+
fi
44+
shift
45+
done
46+
}

pine

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,21 @@
11
#! /usr/bin/env bash
22

33
# Global constants
4-
PINE_VERSION=1.0.0
4+
PINE_VERSION=1.1.0
55
FILE_NOT_FOUND_EX=2
66
LOG_FILE=/tmp/pine_logs/log.txt
7-
SRC_PATH=""
8-
SCRIPT_PATH=""
7+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
8+
SRC_PATH="$PWD"
99
GITIGNORE_REPO="https://github.com/github/gitignore.git"
10-
# Global variables
11-
declare -A map # map for easy searching of names
1210

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
1315

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
6019

6120
# Updates all gitignore files in ${SCRIPTPATH}/gitignore
6221
function update_config_files() {
@@ -167,6 +126,7 @@ function add_config_to_file() {
167126
echo "ERROR: Configuration exists, skipping"
168127
} || {
169128
echo "Adding configuration for $arg"
129+
echo "" >> ${SRC_PATH}/.gitignore
170130
echo -e "#### ${1} ##########################" >> ${SRC_PATH}/.gitignore
171131
echo -e "#### DO NOT DELETE PRECEDING LINE" >> ${SRC_PATH}/.gitignore
172132
echo -e "#### PINE" >> ${SRC_PATH}/.gitignore
@@ -195,11 +155,10 @@ function remove_config_from_file() {
195155
echo "$currentcontent" | awk -v a="$1" -f ${SCRIPTPATH}/utilities/remove.awk > ${SRC_PATH}/.gitignore
196156
}
197157

158+
198159
function init() {
199160
set -e
200-
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
201-
SRC_PATH="$PWD"
202-
161+
203162
# Checks the presence of config files
204163
check_and_update_config_files
205164

@@ -214,9 +173,6 @@ function init() {
214173
mkdir -p /tmp/pine_logs
215174
fi
216175

217-
# Load error.sh or display error and exit
218-
source "${SCRIPTPATH}/inc/error.sh"
219-
220176
load_names
221177
eval $(parse_params "$@") # Parse parameters
222178

@@ -246,8 +202,6 @@ function init() {
246202
list_all_config
247203
exit
248204
fi
249-
250-
251205

252206
# Search each parameter
253207
for arg in "${ARGV[@]}"; do

0 commit comments

Comments
 (0)