Skip to content

Instantly share code, notes, and snippets.

@RomainGehrig
Last active August 25, 2022 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RomainGehrig/2f7a4ee050f670f423bf14585afd1f44 to your computer and use it in GitHub Desktop.
Save RomainGehrig/2f7a4ee050f670f423bf14585afd1f44 to your computer and use it in GitHub Desktop.
Query org-files, select entry and open emacs
# Put the lines below in your .bashrc
# Usage: orgql-open '(todo "TODO")'
# See sexp query format here: https://github.com/alphapapa/org-ql#non-sexp-query-syntax
function orgql-open() {
QUERY=$@
emacsclient -e "(json-encode (org-ql-query :select '(list (cons \"header\" (substring-no-properties (org-get-heading t t))) (cons \"link\" (substring-no-properties (org-store-link nil nil) 0)) (cons \"content\" (substring-no-properties (org-get-entry) 0))) :from (org-agenda-files) :where '$QUERY))"\
| xargs -I % -0 python -c "print(%)" \
| jq -r '.[] | (.link + "\t" + .header + "\t" + (.content|@json))' \
| fzf -d"\t" --with-nth=2 --preview 'cat <(echo {+2}) <(printf {+3} | sed -e "s/^\"//g" -e "s/\"$//g")' \
| cut -z -f1 \
| xargs -0 -I % emacsclient -nc -F '((width . 120) (height . 40))' -e "(progn (org-open-link-from-string \"%\") (recenter-top-bottom 2))"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment