Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zsh support, remove extra output on macOS #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions melee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@
# sudofox/melee.sh

melee() {
MELEE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

current_shell() {
# ps displays current process
# cut isolates shell
# xargs removes leading/trailing whitespace
CUR_SH=$(ps -hp $$ | cut -d ' ' -f 8 | xargs)

case $CUR_SH in
zsh|-zsh)
echo "zsh"
return 0
;;

bash|-bash)
echo "bash"
return 0
;;

*)
echo "unsupported"
return 1
;;
esac
}

case $(current_shell) in
zsh)
MELEE_DIR=${${(%):-%x:h}:h}
;;

bash)
MELEE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
;;

*)
echo -e "melee.sh: Current shell is unsupported."
echo -e " >> Please use one of the following: bash, zsh"
eval "$@"
return $?
;;
esac

sound_util() { # Can be run independently for debugging / verification purposes.
# FFPLAY (ffmpeg)
if type ffplay >/dev/null 2>&1; then
Expand Down Expand Up @@ -59,14 +98,15 @@ melee() {
esac

success() {
( $PLAY_COMMAND "$MELEE_DIR"/sounds/success.wav > /dev/null 2>&1 & disown)
eval "($PLAY_COMMAND $MELEE_DIR/sounds/success.wav > /dev/null 2>&1 & disown 2> /dev/null)"
return 0
}
failure() {
local rc=$?
( $PLAY_COMMAND "$MELEE_DIR"/sounds/failure.wav > /dev/null 2>&1 & disown)
eval "($PLAY_COMMAND $MELEE_DIR/sounds/failure.wav > /dev/null 2>&1 & disown 2> /dev/null)"
return $rc
}

# eval is used here to allow for alias resolution
eval "$@" && success || failure
return $?
Expand Down