From b9949c39be54dd23d7229fd16e73cdea066e68f1 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Sun, 3 Apr 2016 09:58:42 -0700 Subject: [PATCH 1/2] Add support for multiple shell types. Fixes #184 Also add "rb" as an alias to rebuildPatches --- paper | 58 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/paper b/paper index fccd31448b..4808cd5e3e 100755 --- a/paper +++ b/paper @@ -1,7 +1,20 @@ #!/usr/bin/env bash +# resolve shell-specifics +case "$SHELL" in + "/bin/zsh") + RCPATH="$HOME/.zshrc" + SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}" + ;; + *) + RCPATH="$HOME/.bashrc" + if [[ -f "$HOME/.bash_aliases" ]]; then + RCPATH="$HOME/.bash_aliases" + fi + SOURCE="${BASH_SOURCE[0]}" + ;; +esac # get base dir regardless of execution location -SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SOURCE="$(readlink "$SOURCE")" @@ -21,7 +34,7 @@ paperunstash() { } case "$1" in - "rbp" | "rebuild") + "rb" | "rbp" | "rebuild") ( set -e cd "$basedir" @@ -104,14 +117,16 @@ case "$1" in esac ;; "setup") - if [[ -f ~/.bashrc ]] ; then + if [[ -f "$RCPATH" ]] ; then NAME="paper" if [[ ! -z "${2+x}" ]] ; then NAME="$2" fi - (grep "alias $NAME=" ~/.bashrc > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >> ~/.bashrc) + (grep "alias $NAME=" "$RCPATH" > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='.$SOURCE'|g" "$RCPATH") || (echo "alias $NAME='. $SOURCE'" >> "$RCPATH") alias "$NAME=. $SOURCE" echo "You can now just type '$NAME' at any time to access the paper tool." + else + echo "We were unable to setup the paper build tool alias: $RCPATH is missing" fi ;; *) @@ -120,27 +135,30 @@ case "$1" in echo "'setup' command. View below for details. For essential building and patching, you do not need to do the setup." echo "" echo " Normal commands:" - echo " * rbp, rebuild | Rebuild patches, can be called from anywhere." - echo " * p, patch | Apply all patches to the project without building it. Can be run from anywhere." - echo " * j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." + echo " * rb, rbp, rebuild | Rebuild patches, can be called from anywhere." + echo " * p, patch | Apply all patches to the project without building it. Can be run from anywhere." + echo " * j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." echo "" echo " These commands require the setup command before use:" - echo " * r, root | Change directory to the root of the project." - echo " * a. api | Move to the Paper-API directory." - echo " * s, server | Move to the Paper-Server directory." - echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" - echo " | respectively to edit the correct project. Use the argument \"continue\" after" - echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." + echo " * r, root | Change directory to the root of the project." + echo " * a. api | Move to the Paper-API directory." + echo " * s, server | Move to the Paper-Server directory." + echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" + echo " | respectively to edit the correct project. Use the argument \"continue\" after" + echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." echo "" - echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" - echo " | . ./paper setup" - echo " | After you run this command you'll be able to just run 'paper' from anywhere." - echo " | The default name for the resulting alias is 'paper', you can give an argument to override" - echo " | this default, such as:" - echo " | . ./paper setup example" - echo " | Which will allow you to run 'example' instead." + echo " * setup | Add an alias to $RCPATH to allow full functionality of this script. Run as:" + echo " | . ./paper setup" + echo " | After you run this command you'll be able to just run 'paper' from anywhere." + echo " | The default name for the resulting alias is 'paper', you can give an argument to override" + echo " | this default, such as:" + echo " | . ./paper setup example" + echo " | Which will allow you to run 'example' instead." ;; esac +unset RCPATH +unset SOURCE +unset basedir unset -f paperstash unset -f paperunstash From 2c0c9e081c7a84857d52e3e3024321fd78fdacec Mon Sep 17 00:00:00 2001 From: DemonWav Date: Sun, 3 Apr 2016 21:36:19 -0500 Subject: [PATCH 2/2] Fix paper build tool to work with zsh. --- paper | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/paper b/paper index 4808cd5e3e..76dacd4089 100755 --- a/paper +++ b/paper @@ -1,24 +1,25 @@ #!/usr/bin/env bash # resolve shell-specifics -case "$SHELL" in - "/bin/zsh") - RCPATH="$HOME/.zshrc" - SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}" +case "$(echo "$SHELL" | sed 's|/usr||g')" in + "/bin/zsh") + RCPATH="$HOME/.zshrc" + SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}" ;; - *) - RCPATH="$HOME/.bashrc" - if [[ -f "$HOME/.bash_aliases" ]]; then - RCPATH="$HOME/.bash_aliases" - fi - SOURCE="${BASH_SOURCE[0]}" + *) + RCPATH="$HOME/.bashrc" + if [[ -f "$HOME/.bash_aliases" ]]; then + RCPATH="$HOME/.bash_aliases" + fi + SOURCE="${BASH_SOURCE[0]}" ;; esac + # get base dir regardless of execution location while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") basedir=$(dirname "$SOURCE") @@ -64,6 +65,13 @@ case "$1" in fi ) ;; + "m" | "mcdev") + ( + set -e + cd "$basedir" + scripts/makemcdevsrc.sh "$basedir" + ) + ;; "r" | "root") cd "$basedir" ;; @@ -122,7 +130,7 @@ case "$1" in if [[ ! -z "${2+x}" ]] ; then NAME="$2" fi - (grep "alias $NAME=" "$RCPATH" > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='.$SOURCE'|g" "$RCPATH") || (echo "alias $NAME='. $SOURCE'" >> "$RCPATH") + (grep "alias $NAME=" "$RCPATH" > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" "$RCPATH") || (echo "alias $NAME='. $SOURCE'" >> "$RCPATH") alias "$NAME=. $SOURCE" echo "You can now just type '$NAME' at any time to access the paper tool." else @@ -138,6 +146,7 @@ case "$1" in echo " * rb, rbp, rebuild | Rebuild patches, can be called from anywhere." echo " * p, patch | Apply all patches to the project without building it. Can be run from anywhere." echo " * j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere." + echo " * m, mcdev | Setup decompiled sources for non-modified NMS files to be imported into an IDE. Can be run from anywhere." echo "" echo " These commands require the setup command before use:" echo " * r, root | Change directory to the root of the project."