alphapapa / org-rifle

Rifle through your Org-mode buffers and acquire your target
GNU General Public License v3.0
501 stars 30 forks source link

command-line client #66

Open ArneBab opened 3 years ago

ArneBab commented 3 years ago

org-rifle is hands-down the best way to find information in org-mode files.

To make it easier to use it for a general shared knowledge-base, the requirement to run it from within Emacs is limiting, though, because that excludes many wonderful colleagues who do not use Emacs as their environment. Therefore it would be great to have a command-line client to org-rifle.

Maybe a wrapper around Emacs which directly runs org-rifle to make Emacs transparent in the process.

Something like the following script (named know) that can be linked into ~/.local/bin and gets its configuration from a setup.el-file in the directory it is installed in:

#!/usr/bin/env bash

H="$(dirname "$(realpath "${0}")")"
emacsclient -nw -e '(progn (raise-frame)(select-frame-set-input-focus (selected-frame))(know))' 2>/dev/null || HOME="${H}" emacs -nw -l setup.el --visit know.org -f org-mode -f know

setup.el:

;;; setup.el
(defvar knowledge-base-filepath "~/know.org" "Path to the file to read and write the knowledge base")
(require 'use-package)
(use-package org
  :custom
  (org-src-fontify-natively t))
(use-package org-capture :ensure org)
(use-package helm-org-rifle :ensure t
  :config
  (defun know()
    (interactive)
    (with-current-buffer (find-file knowledge-base-filepath)
      (helm-org-rifle)))
  (add-to-list 'org-capture-templates
        `("k" "knowlege base entry" entry
          (file ,knowledge-base-filepath)
         "")
        t))
;;; setup.el ends here

With this you can always call know from anywhere in the commandline and rifle through the knowledge base. It’s much nicer than searching in a shared wiki.

I have the know.org file in versiontracking, so my knowledge-base entries are accessible to others after the next push.

alphapapa commented 3 years ago

This is an interesting idea, yes. I'd generally recommend using org-ql as the base rather than org-rifle. See, e.g.

The hard parts, it seems to me, are providing enough data to be useful outside of Emacs, and allowing users to easily jump to the entries in Emacs. However, for your use case, maybe that's not necessary. And using org-ql you can easily return whatever data you want from a query.