Created
January 13, 2023 10:06
-
-
Save pesterhazy/b954a7e7ee6d6a4c2bd08eabd41bd863 to your computer and use it in GitHub Desktop.
Open file in emacsclient with optional line number. Start emacs if it's not running yet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
result=0 | |
if [[ $# == 1 ]]; then | |
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n "$1" || result=$? | |
elif [[ $# == 2 ]]; then | |
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n +"$2" "$1" || result=$? | |
else | |
echo Unexpected args | |
exit 1 | |
fi | |
# Didn't work? Let's start emacs first | |
if [[ $result != 0 ]]; then | |
echo Starting new Emacs... | |
open -a Emacs | |
for i in `seq 50`; do | |
result=0 | |
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e "(+ 1 2)" >/dev/null 2>&1 || result=$? | |
if [[ $result == 0 ]]; then | |
break | |
fi | |
sleep 0.1 | |
done | |
fi | |
# Rerun initial command | |
result=0 | |
if [[ $# == 1 ]]; then | |
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n "$1" || result=$? | |
elif [[ $# == 2 ]]; then | |
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n +"$2" "$1" || result=$? | |
else | |
echo Unexpected args | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment