bin/org-capture: reformat & improve daemon cleanup
Ensures the temporary daemon is killed after org-capture is finished.
This commit is contained in:
parent
3284356fc2
commit
6c8df7c6bb
1 changed files with 14 additions and 15 deletions
|
@ -10,34 +10,33 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
emacsclient --eval '(kill-emacs)'
|
emacsclient --eval '(let (kill-emacs-hook) (kill-emacs))'
|
||||||
}
|
}
|
||||||
|
|
||||||
# If emacs isn't running, we start a temporary daemon, solely for this window.
|
# If emacs isn't running, we start a temporary daemon, solely for this window.
|
||||||
daemon=
|
if ! emacsclient -e nil; then
|
||||||
if ! pgrep emacs >/dev/null; then
|
emacs --daemon
|
||||||
emacs --daemon
|
trap cleanup EXIT INT TERM
|
||||||
trap cleanup EXIT INT TERM
|
daemon=1
|
||||||
daemon=1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# org-capture key mapped to argument flags
|
# org-capture key mapped to argument flags
|
||||||
keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
|
keys=$(emacsclient -e "(+org-capture-available-keys)" | cut -d '"' -f2)
|
||||||
while getopts $keys opt; do
|
while getopts $keys opt; do
|
||||||
key="\"$opt\""
|
key="\"$opt\""
|
||||||
break
|
break
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
[ -t 0 ] && str="$*" || str=$(cat)
|
[ -t 0 ] && str="$*" || str=$(cat)
|
||||||
|
|
||||||
if [[ $daemon ]]; then
|
if [[ $daemon ]]; then
|
||||||
emacsclient -a "" \
|
emacsclient -a "" \
|
||||||
-c -F '((name . "org-capture") (width . 70) (height . 25) (transient . t))' \
|
-c -F '((name . "org-capture") (width . 70) (height . 25) (transient . t))' \
|
||||||
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|
-e "(+org-capture/open-frame \"$str\" ${key:-nil} t)"
|
||||||
else
|
else
|
||||||
# Non-daemon servers flicker a lot if frames are created from terminal, so
|
# Non-daemon servers flicker a lot if frames are created from terminal, so we
|
||||||
# we do it internally instead.
|
# do it internally instead.
|
||||||
emacsclient -a "" \
|
emacsclient -a "" \
|
||||||
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|
-e "(+org-capture/open-frame \"$str\" ${key:-nil})"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue