Skip to content

Instantly share code, notes, and snippets.

@mtungusov
Created December 20, 2023 08:55
Show Gist options
  • Select an option

  • Save mtungusov/7c2d2b7e52b51e98906874fe7adfcfa3 to your computer and use it in GitHub Desktop.

Select an option

Save mtungusov/7c2d2b7e52b51e98906874fe7adfcfa3 to your computer and use it in GitHub Desktop.
Emacs.app from CLI
#!/bin/sh
##
# from: https://gist.github.com/railwaycat/4043945
##
emacs_app=/usr/local/opt/emacs-mac/Emacs.app
if [ ! -x $emacs_app ]; then
echo "Emacs.app not found" >&2
exit 1
fi
/usr/bin/osascript -e "tell application \"$emacs_app\" to activate" &
if [ $# -gt 0 ]; then
tempfiles=()
while IFS= read -r filename; do
if [ ! -f "$filename" ]; then
tempfiles+=("$filename")
/usr/bin/touch "$filename"
fi
file=$(echo $(cd $(dirname "$filename") && pwd -P)/$(basename "$filename"))
/usr/bin/osascript -e "tell application \"$emacs_app\" to open POSIX file \"$file\""
done <<< "$(printf '%s\n' "$@")"
for tempfile in "${tempfiles[@]}"; do
[ ! -s "$tempfile" ] && /bin/rm "$tempfile"
done
fi &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment