2019-06-08 07:27:36 +02:00
|
|
|
#!/usr/bin/env sh
|
2017-04-22 01:49:44 -04:00
|
|
|
|
|
|
|
# Open an org-capture popup frame from the shell. This opens a temporary emacs
|
|
|
|
# daemon if emacs isn't already running.
|
|
|
|
#
|
2019-03-29 23:49:47 -04:00
|
|
|
# Usage: org-capture [-k KEY] [MESSAGE]
|
2017-04-22 01:49:44 -04:00
|
|
|
# Examples:
|
2019-03-29 23:49:47 -04:00
|
|
|
# org-capture -k n "To the mind that is still, the whole universe surrenders."
|
2017-04-22 01:49:44 -04:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cleanup() {
|
2018-06-24 15:16:17 +02:00
|
|
|
emacsclient --eval '(let (kill-emacs-hook) (kill-emacs))'
|
2017-04-22 01:49:44 -04:00
|
|
|
}
|
|
|
|
|
2017-10-02 20:02:10 +02:00
|
|
|
# If emacs isn't running, we start a temporary daemon, solely for this window.
|
2021-11-24 22:03:21 +01:00
|
|
|
if ! emacsclient --suppress-output --eval nil 2>/dev/null; then
|
|
|
|
echo "No Emacs daemon/server is available! Starting one..."
|
2018-06-24 15:16:17 +02:00
|
|
|
emacs --daemon
|
|
|
|
trap cleanup EXIT INT TERM
|
2017-04-22 01:49:44 -04:00
|
|
|
fi
|
|
|
|
|
2017-10-02 20:02:10 +02:00
|
|
|
# org-capture key mapped to argument flags
|
2019-03-29 23:49:47 -04:00
|
|
|
# keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
|
2020-02-10 11:36:55 +01:00
|
|
|
while getopts "hk:" opt; do
|
|
|
|
key="\"$OPTARG\""
|
2018-06-24 15:16:17 +02:00
|
|
|
break
|
2017-10-02 20:02:10 +02:00
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2021-05-12 16:18:08 -04:00
|
|
|
# use remaining args, else read from stdin if passed a single dash
|
2021-03-07 00:48:32 -08:00
|
|
|
str="$*"
|
2021-05-12 16:18:08 -04:00
|
|
|
case "$str" in
|
|
|
|
-) str=$(cat) ;;
|
|
|
|
esac
|
2017-10-02 20:02:10 +02:00
|
|
|
|
2020-08-21 03:04:14 -04:00
|
|
|
# Fix incompatible terminals that cause odd 'not a valid terminal' errors
|
2021-02-25 13:56:41 -05:00
|
|
|
[ "$TERM" = "alacritty" ] && export TERM=xterm-256color
|
2020-08-21 03:04:14 -04:00
|
|
|
|
2021-11-24 22:03:21 +01:00
|
|
|
# Non-daemon servers flicker a lot if frames are created from terminal, so we do
|
|
|
|
# it internally instead.
|
|
|
|
emacsclient -a "" \
|
|
|
|
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|