doom-emacs/bin/org-capture

44 lines
1.2 KiB
Text
Raw Permalink Normal View History

#!/usr/bin/env sh
2017-04-22 05:49:44 +00:00
# Open an org-capture popup frame from the shell. This opens a temporary emacs
# daemon if emacs isn't already running.
#
# Usage: org-capture [-k KEY] [MESSAGE]
2017-04-22 05:49:44 +00:00
# Examples:
# org-capture -k n "To the mind that is still, the whole universe surrenders."
2017-04-22 05:49:44 +00:00
set -e
cleanup() {
emacsclient --eval '(let (kill-emacs-hook) (kill-emacs))'
2017-04-22 05:49:44 +00:00
}
# If emacs isn't running, we start a temporary daemon, solely for this window.
if ! emacsclient --suppress-output --eval nil 2>/dev/null; then
echo "No Emacs daemon/server is available! Starting one..."
emacs --daemon
trap cleanup EXIT INT TERM
2017-04-22 05:49:44 +00:00
fi
# org-capture key mapped to argument flags
# keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
2020-02-10 10:36:55 +00:00
while getopts "hk:" opt; do
key="\"$OPTARG\""
break
done
shift $((OPTIND-1))
# use remaining args, else read from stdin if passed a single dash
str="$*"
case "$str" in
-) str=$(cat) ;;
esac
# Fix incompatible terminals that cause odd 'not a valid terminal' errors
[ "$TERM" = "alacritty" ] && export TERM=xterm-256color
# 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})"