diff --git a/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md similarity index 100% rename from ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7561779 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,13 @@ +**Pull Request Label:** +* [ ] Bug +* [ ] New feature +* [ ] Enhancement +* [ ] New component +* [ ] Typo + +**Pull Request Checklist:** +- [ ] Have you followed the [guidelines for contributing](https://github.com/alexanderepstein/Bash-Snippet/blob/master/CONTRIBUTING.md)? +- [ ] Have you checked that there aren't other open [pull requests](https://github.com/Homebrew/homebrew-core/pulls) for the same fix or component? +- [ ] Have you ran the tests locally with `bats tests`? + +----- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7261bff..5a265af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ If you've noticed a bug or have a question, search the issue tracker to see if someone else in the community has already created a ticket. If not, go ahead and make one! -#### Otherwise if implementing a fix or feature go through these steps +#### Otherwise if implementing a fix, feature or new component go through these steps #### 1. Fork & Clone The Repository * Fork the repository * It is assumed you are on either a Unix or Linux system in which are there are no dependencies @@ -16,14 +16,25 @@ git clone https://github.com/yourusernamehere/Bash-Snippets ``` -#### 2. Implement your fix or feature +#### 2. Implement your fix, feature or new component -At this point, you're ready to make your changes! Feel free to ask for help; everyone is a beginner at first :smile_cat: +###### Fix/Feature +At this point, you're ready to make your changes! + +###### New Component +* Decide on a short but sweet name for your tool +* Create a folder in the Bash-Snippets root directory named after the tool +* Copy over the Bash-Snippets tool [skeleton](https://github.com/alexanderepstein/Bash-Snippet/blob/master/skeleton) to the newly created folder +* Rename the skeleton in the new directory to the name of the tool +* Using newly copied over file as a basis (with the name of your tool) code your new component! + +Feel free to ask for help; everyone is a beginner at first :smile_cat: Make sure to make your commit messages informative and concise. + #### 3. Check The Script Runtime -If you changed the weather script for example try running it and see if it works as intended. +If you changed the weather script for example try running it and see if it works as intended. Run ```bats tests``` when inside the Bash-Snippets directory to test the tools. If you added a new script/tool test it to see if it works. #### 4. Create A Pull Request diff --git a/README.md b/README.md index fcbba26..c2be30a 100644 --- a/README.md +++ b/README.md @@ -295,11 +295,7 @@ brew install bash-snippets # installs all tools brew install bash-snippets --without-all-tools --with-newton --with-weather # specifying install for individual tools ``` -### For Sparrowhub users -```bash -sparrow plg install [tool] -``` -### For Arch Linux Users +### Arch Linux (AUR) There is an AUR package for bash-snippets located [here](https://aur.archlinux.org/packages/bash-snippets/) Download the tarball Install the program with @@ -308,13 +304,27 @@ makepkg -Acs sudo pacman -U bash-snippets.tar.gz ``` -### Otherwise +### Sparrowhub +```bash +sparrow plg install [tool] +``` -* First clone the repository: ```git clone https://github.com/alexanderepstein/Bash-Snippets``` +### Git Install -* Then cd into the cloned directory: ```cd Bash-Snippets``` +* First clone the repository: +```bash +git clone https://github.com/alexanderepstein/Bash-Snippets +``` -* Git checkout to the latest stable release ```git checkout v1.17.3``` +* Then cd into the cloned directory: +```bash +cd Bash-Snippets +``` + +* Git checkout to the latest stable release +```bash +git checkout v1.17.3 +``` * Run the guided install script with ```bash @@ -339,7 +349,7 @@ this will let you choose which scripts to install brew upgrade bash-snippets ``` -### Otherwise +### Git Update With any of the installed tools you can automate the update by running it with the -u option or passing in update as the arguments Ex. @@ -359,10 +369,16 @@ This will clone the repository and install the new versions of scripts that were brew uninstall bash-snippets ``` -### Otherwise -* If you don't have the Bash-Snippets folder anymore clone the repository: ```git clone https://github.com/alexanderepstein/Bash-Snippets``` +### Git Uninstall +* If you don't have the Bash-Snippets folder anymore clone the repository: +```bash +git clone https://github.com/alexanderepstein/Bash-Snippets +``` -* cd into the Bash-Snippets directory: ```cd Bash-Snippets``` +* cd into the Bash-Snippets directory: +```bash +cd Bash-Snippets +``` #### To go through a guided uninstall ```bash diff --git a/skeleton b/skeleton new file mode 100755 index 0000000..df43a2c --- /dev/null +++ b/skeleton @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Author: Alexander Epstein https://github.com/alexanderepstein +currentVersion="1.17.3" +configuredClient="" + +## This function determines which http get tool the system has installed and returns an error if there isnt one +getConfiguredClient() +{ + if command -v curl &>/dev/null; then + configuredClient="curl" + elif command -v wget &>/dev/null; then + configuredClient="wget" + elif command -v http &>/dev/null; then + configuredClient="httpie" + elif command -v fetch &>/dev/null; then + configuredClient="fetch" + else + echo "Error: This tool reqires either curl, wget, httpie or fetch to be installed." >&2 + return 1 + fi +} + +## Allows to call the users configured client without if statements everywhere +httpGet() +{ + case "$configuredClient" in + curl) curl -A curl -s "$@" ;; + wget) wget -qO- "$@" ;; + httpie) http -b GET "$@" ;; + fetch) fetch -q "$@" ;; + esac +} + +update() +{ + # Author: Alexander Epstein https://github.com/alexanderepstein + # Update utility version 1.2.0 + # To test the tool enter in the defualt values that are in the examples for each variable + repositoryName="Bash-Snippets" #Name of repostiory to be updated ex. Sandman-Lite + githubUserName="alexanderepstein" #username that hosts the repostiory ex. alexanderepstein + nameOfInstallFile="install.sh" # change this if the installer file has a different name be sure to include file extension if there is one + latestVersion=$(httpGet https://api.github.com/repos/$githubUserName/$repositoryName/tags | grep -Eo '"name":.*?[^\\]",'| head -1 | grep -Eo "[0-9.]+" ) #always grabs the tag without the v option + + if [[ $currentVersion == "" || $repositoryName == "" || $githubUserName == "" || $nameOfInstallFile == "" ]]; then + echo "Error: update utility has not been configured correctly." >&2 + exit 1 + elif [[ $latestVersion == "" ]]; then + echo "Error: no active internet connection" >&2 + exit 1 + else + if [[ "$latestVersion" != "$currentVersion" ]]; then + echo "Version $latestVersion available" + echo -n "Do you wish to update $repositoryName [Y/n]: " + read -r answer + if [[ "$answer" == [Yy] ]]; then + cd ~ || { echo 'Update Failed'; exit 1; } + if [[ -d ~/$repositoryName ]]; then rm -r -f $repositoryName || { echo "Permissions Error: try running the update as sudo"; exit 1; } ; fi + git clone "https://github.com/$githubUserName/$repositoryName" || { echo "Couldn't download latest version"; exit 1; } + cd $repositoryName || { echo 'Update Failed'; exit 1; } + git checkout "v$latestVersion" 2> /dev/null || git checkout "$latestVersion" 2> /dev/null || echo "Couldn't git checkout to stable release, updating to latest commit." + chmod a+x install.sh #this might be necessary in your case but wasnt in mine. + ./$nameOfInstallFile "update" || exit 1 + cd .. + rm -r -f $repositoryName || { echo "Permissions Error: update succesfull but cannot delete temp files located at ~/$repositoryName delete this directory with sudo"; exit 1; } + else + exit 1 + fi + else + echo "$repositoryName is already the latest version" + fi + fi +} + +checkInternet() +{ + httpGet github.com > /dev/null 2>&1 || { echo "Error: no active internet connection" >&2; return 1; } # query github with a get request +} + +usage() +{ + cat <&2 + exit 1 + ;; + h) usage + exit 0 + ;; + v) echo "Version $currentVersion" + exit 0 + ;; + u) update + exit 0 + ;; + :) echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# special set of first arguments that have a specific behavior across tools +if [[ $# == "0" ]]; then + usage ## if calling the tool with no flags and args chances are you want to return usage + exit 0 +elif [[ $# == "1" ]]; then + if [[ $1 == "update" ]]; then + getConfiguredClient || exit 1 + checkInternet || exit 1 + update || exit 1 + exit 0 + elif [[ $1 == "help" ]]; then + usage + exit 0 + fi +fi + +## The rest of the conditions and code would go here