-
Notifications
You must be signed in to change notification settings - Fork 1
/
pullover-start-or-finish
executable file
·42 lines (34 loc) · 1.46 KB
/
pullover-start-or-finish
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
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# This is the wrapper script that should be bound to a global shortcut to start/finish a pullover
# editing session.
#
# We use ScriptingBridge/AppleScript to control other apps (activating them, copying/pasting texts).
# When Emacs app is the topmost app in the process hierarchy (e.g. `open /Applications/Emacs.app`),
# the first control attempt (after some idle period) suffers a significant delay (up to 10+ seconds)
# on a per-app basis. This delay doesn't exist when the topmost app is not Emacs (e.g. running
# `/Applications/Emacs.app/Contents/MacOS/Emacs` from iTerm). Therefore we use this script to keep
# these parts under another app (e.g. karabiner_console_user_server, or other shortcut-binding
# apps).
#
# TODO: Figure out why. File an Emacs bug. (Note that this happens even to the EmacsMac fork.)
set -euo pipefail
DIR=$(dirname "$BASH_SOURCE")
HERE=$(cd "$DIR"; pwd)
PULLOVER_TMP_DIR="$HOME/.emacs.d/.pullover"
if [ -f "$PULLOVER_TMP_DIR"/emacsclient_cmd ]; then
EMACSCLIENT=$(cat "$PULLOVER_TMP_DIR"/emacsclient_cmd)
else
EMACSCLIENT='emacsclient'
fi
PID=$($EMACSCLIENT -e '(pullover-checkpoint-clipboard)')
echo "Emacs PID $PID"
echo "Copying ..."
APP_IN=$("$HERE"/pullover-bin copy-text "$PID")
echo "<- $APP_IN"
echo "Opening Emacs ..."
APP_OUT=$($EMACSCLIENT -e '(pullover-start-or-finish "'"$APP_IN"'")')
echo "-> $APP_OUT"
if [ "$APP_OUT" != "started" ]; then
echo "Pasting ..."
"$HERE"/pullover-bin paste-text "$APP_OUT"
fi