bin/org-capture: improve stability + add stdin support
This commit is contained in:
parent
4c148ea580
commit
898d1f225a
1 changed files with 21 additions and 6 deletions
|
@ -9,20 +9,35 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
key="${1:-n}"
|
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
emacsclient --eval '(kill-emacs)'
|
emacsclient --eval '(kill-emacs)'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If emacs isn't running, we start a temporary daemon, solely for this window.
|
||||||
|
daemon=
|
||||||
if ! pgrep emacs >/dev/null; then
|
if ! pgrep emacs >/dev/null; then
|
||||||
emacs --daemon
|
emacs --daemon
|
||||||
trap cleanup EXIT INT TERM
|
trap cleanup EXIT INT TERM
|
||||||
|
daemon=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO Allow piping from stdin
|
# org-capture key mapped to argument flags
|
||||||
|
keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
|
||||||
|
while getopts $keys opt; do
|
||||||
|
key="\"$opt\""
|
||||||
|
break
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
emacsclient -c \
|
[ -t 0 ] && str="$*" || str=$(cat)
|
||||||
-F '((name . "org-capture") (width . 70) (height . 25))' \
|
|
||||||
--eval "(+org-capture/dwim \"$2\" \"$key\")"
|
|
||||||
|
|
||||||
|
if [[ $daemon ]]; then
|
||||||
|
emacsclient -a "" \
|
||||||
|
-c -F '((name . "org-capture") (width . 70) (height . 25))' \
|
||||||
|
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|
||||||
|
else
|
||||||
|
# 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})"
|
||||||
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue