Skip to content

Commit

Permalink
Merge pull request #3 from suyashmahar/version/1.1
Browse files Browse the repository at this point in the history
🎉 Version 1.1
  • Loading branch information
suyashmahar authored Jun 20, 2018
2 parents 728ef39 + 8a2f787 commit 058f5d1
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 67 deletions.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Gitignore configurations for emacs
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el
18 changes: 12 additions & 6 deletions HELP.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Options:
-r --remove Remove configuration for all config files specified from
.gitignore file in current directory.

-u --update Update local configuration files and exit.
-u --update Update local configuration files and exit.

--list List all configuration files present in current directory's
.gitignore file

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

Expand All @@ -18,11 +21,14 @@ Examples
========

To add configuration for java, c:
pine c java
pine c java

To remove configuration for java:
pine -r java

To remove configuration for java
pine -r java
To list all configurations present in current directory's .gitignore file:
pine --list

To update
pine --update
To update:
pine --update

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Run the following command in your terminal to download and install pine.

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

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

Usage
Expand Down
31 changes: 31 additions & 0 deletions custpathhandler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#! /usr/bin/env bash

# Contains functions for handling all custom .gitignore
# directory related features

function load_dirs() {
if [ -f "${SCRIPTPATH}/dirs.list" ]; then
dirNames=`cat ${SCRIPTPATH}/dirs.list`
else
echo "WARNING: Directory list not compiled"
echo "INFO: Adding default default gitignore directories."

# Add 2 default locations present in github's repository
echo ":${SCRIPTPATH}/gitignore" >> "${SCRIPTPATH}/dirs.list"
if [ -d "${SCRIPTPATH}/global" ]; then
echo "global:${SCRIPTPATH}/global" >> "${SCRIPTPATH}/dirs.list"
fi

load_dirs
return
fi

# Read each line from dirs.list and add an entry to map.
# Lines in dirs.list have pattern:
# alias:path
while read -r line; do
lineSplit=("$line")
dirNameMap["${lineSplit[0]}"]="${lineSplit[1]}"
done < "${SCRIPTPATH}/dirs.list"

}
46 changes: 46 additions & 0 deletions paramparser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /usr/bin/env bash

# From: https://stackoverflow.com/a/38153758/6556360
# parse the arguments.
parse_params ()
{
local existing_named
local ARGV=()
echo "local ARGV=(); "
while [[ "$1" != "" ]]; do
# If equals delimited named parameter
if [[ "$1" =~ ^..*=..* ]]; then
# key is part before first =
local _key=$(echo "$1" | cut -d = -f 1)
# val is everything after key and = (protect from param==value error)
local _val="${1/$_key=}"
# remove dashes from key name
_key=${_key//\-}
# search for existing parameter name
if (echo "$existing_named" | grep "\b$_key\b" >/dev/null); then
# if name already exists then it's a multi-value named parameter
# re-declare it as an array if needed
if ! (declare -p _key 2> /dev/null | grep -q 'declare \-a'); then
echo "$_key=(\"\$$_key\");"
fi
# append new value
echo "$_key+=('$_val');"
else
# single-value named parameter
echo "local $_key=\"$_val\";"
existing_named=" $_key"
fi
# If standalone named parameter
elif [[ "$1" =~ ^\-. ]]; then
# remove dashes
local _key=${1//\-}
echo "local $_key=\"$_key\";"
# non-named parameter
else
# escape asterisk to prevent bash asterisk expansion
_escaped=${1/\*/\'\"*\"\'}
echo "ARGV+=('$_escaped');"
fi
shift
done
}
72 changes: 13 additions & 59 deletions pine
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
#! /usr/bin/env bash

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

# Import functions
source "${SCRIPTPATH}/paramparser.sh" # For parameter parsing
source "${SCRIPTPATH}/inc/error.sh" # For error handling
source "${SCRIPTPATH}/custpathhandler.sh" # For handling custom dir

# -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
# From: https://stackoverflow.com/a/38153758/6556360
# parse the arguments.
parse_params ()
{
local existing_named
local ARGV=()
echo "local ARGV=(); "
while [[ "$1" != "" ]]; do
# If equals delimited named parameter
if [[ "$1" =~ ^..*=..* ]]; then
# key is part before first =
local _key=$(echo "$1" | cut -d = -f 1)
# val is everything after key and = (protect from param==value error)
local _val="${1/$_key=}"
# remove dashes from key name
_key=${_key//\-}
# search for existing parameter name
if (echo "$existing_named" | grep "\b$_key\b" >/dev/null); then
# if name already exists then it's a multi-value named parameter
# re-declare it as an array if needed
if ! (declare -p _key 2> /dev/null | grep -q 'declare \-a'); then
echo "$_key=(\"\$$_key\");"
fi
# append new value
echo "$_key+=('$_val');"
else
# single-value named parameter
echo "local $_key=\"$_val\";"
existing_named=" $_key"
fi
# If standalone named parameter
elif [[ "$1" =~ ^\-. ]]; then
# remove dashes
local _key=${1//\-}
echo "local $_key=\"$_key\";"
# non-named parameter
else
# escape asterisk to prevent bash asterisk expansion
_escaped=${1/\*/\'\"*\"\'}
echo "ARGV+=('$_escaped');"
fi
shift
done
}
# -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
# Global variables
declare -A map # map for easy searching of names
declare -A dirNameMap # map for easy searching of names

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


function init() {
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
SRC_PATH="$PWD"


# Checks the presence of config files
check_and_update_config_files

Expand All @@ -214,9 +173,6 @@ function init() {
mkdir -p /tmp/pine_logs
fi

# Load error.sh or display error and exit
source "${SCRIPTPATH}/inc/error.sh"

load_names
eval $(parse_params "$@") # Parse parameters

Expand Down Expand Up @@ -246,8 +202,6 @@ function init() {
list_all_config
exit
fi



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

0 comments on commit 058f5d1

Please sign in to comment.