Last active
August 25, 2022 07:24
-
-
Save RomainGehrig/2f7a4ee050f670f423bf14585afd1f44 to your computer and use it in GitHub Desktop.
Query org-files, select entry and open emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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