-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemacs.darwin
More file actions
executable file
·32 lines (27 loc) · 1.08 KB
/
emacs.darwin
File metadata and controls
executable file
·32 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
set -ex
# This version works with the homebrew build of emacs
emacs_server_pattern="Emacs.app/Contents/MacOS/Emacs"
# Using the cask version of Emacs
emacs_server="/Applications/${emacs_server_pattern}"
emacs_client="/usr/local/bin/emacsclient"
if [[ $# -gt 1 ]]; then
if [[ "$1" == "-batch" ]] || [[ "$1" == "--batch" ]] || [[ "$1" == "-Q" ]]; then
#echo "Emacs compiler mode with: '$emacs_server $@'"
exec "${emacs_server}" "$@"
exit
fi
fi
server_pid="$(ps aux | grep -v grep | grep -Ei "${emacs_server_pattern}" | awk '{print $2}')"
# Check if there is already an emacs process (has to be written like this)
if [[ ! -z "${server_pid}" ]]; then
which osascript > /dev/null 2>&1 && \
osascript -e 'tell application "Emacs" to activate'
# Get the number of all frames
num_frames="$(${emacs_client} -e '(length (frame-list))')"
if [[ ${num_frames} -lt 2 ]]; then args=-nc; else args=-n; fi
exec "${emacs_client}" "${args}" --quiet --no-wait "$@" &
else
echo "Initializing emacs server"
exec "${emacs_server}" --no-splash "$@" &
fi