Fix paper build tool to work with zsh.

This commit is contained in:
DemonWav 2016-04-03 21:36:19 -05:00 committed by kashike
parent 13ca1593c5
commit afc619e188

37
paper
View File

@ -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."