2019-06-08 13:27:36 +08:00
|
|
|
#!/usr/bin/env sh
|
2017-04-22 13:49:44 +08:00
|
|
|
|
|
|
|
# Open an org-capture popup frame from the shell. This opens a temporary emacs
|
|
|
|
# daemon if emacs isn't already running.
|
|
|
|
#
|
2019-03-30 11:49:47 +08:00
|
|
|
# Usage: org-capture [-k KEY] [MESSAGE]
|
2017-04-22 13:49:44 +08:00
|
|
|
# Examples:
|
2019-03-30 11:49:47 +08:00
|
|
|
# org-capture -k n "To the mind that is still, the whole universe surrenders."
|
2017-04-22 13:49:44 +08:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cleanup() {
|
2018-06-24 21:16:17 +08:00
|
|
|
emacsclient --eval '(let (kill-emacs-hook) (kill-emacs))'
|
2017-04-22 13:49:44 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 02:02:10 +08:00
|
|
|
# If emacs isn't running, we start a temporary daemon, solely for this window.
|
2018-06-24 21:16:17 +08:00
|
|
|
if ! emacsclient -e nil; then
|
|
|
|
emacs --daemon
|
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
daemon=1
|
2017-04-22 13:49:44 +08:00
|
|
|
fi
|
|
|
|
|
2017-10-03 02:02:10 +08:00
|
|
|
# org-capture key mapped to argument flags
|
2019-03-30 11:49:47 +08:00
|
|
|
# keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
|
|
|
|
while getopts hk opt; do
|
2018-06-24 21:16:17 +08:00
|
|
|
key="\"$opt\""
|
|
|
|
break
|
2017-10-03 02:02:10 +08:00
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
[ -t 0 ] && str="$*" || str=$(cat)
|
|
|
|
|
2019-06-03 19:21:11 +08:00
|
|
|
if [ $daemon ]; then
|
2018-06-24 21:16:17 +08:00
|
|
|
emacsclient -a "" \
|
|
|
|
-c -F '((name . "org-capture") (width . 70) (height . 25) (transient . t))' \
|
2019-03-30 11:49:47 +08:00
|
|
|
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|
2017-10-03 02:02:10 +08:00
|
|
|
else
|
2018-06-24 21:16:17 +08: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})"
|
2017-10-03 02:02:10 +08:00
|
|
|
fi
|