From cf030fa8d5f664421cb96600a9aadf43f603a96f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 11 Mar 2021 06:14:54 +0100 Subject: [PATCH] Add the org-clock-waybar-output-task function It outputs the generated JSON string to the standard output so it can be used directly from the command line, e.g. using `emacsclient`. --- README.md | 24 +++++++++++++++++++++--- org-clock-waybar.el | 8 ++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b86183..fd7be1a 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ Put `org-clock-waybar.el` somewhere in your `load-path`, and `(require 'org-cloc MELPA version may come soon. -You can set the file to be written by customizing `org-clock-waybar-filename`; it defaults to `$XDG_CACHE_HOME/waybar-current-task.json` (`$XDG_CACHE_HOME` defaults to `$HOME/.cache` on XDG compatible systems, like Linux.) +You can set the file to be written by customizing `org-clock-waybar-filename`; it defaults to +`$XDG_CACHE_HOME/waybar-current-task.json` (`$XDG_CACHE_HOME` defaults to `$HOME/.cache` on XDG +compatible systems, like Linux.) ## Waybar configuration To add the current task to Waybar, add this snippet to your config: -``` +```json "custom/org": { "format": " {}", "return-type": "json", @@ -21,7 +23,23 @@ To add the current task to Waybar, add this snippet to your config: } ``` -Then, add `custom/org` to `modules-left`/`modules-center`/`module-right` if your bar’s configuration. You can find a minimal working configuration in the [`examples`](./examples) directory. +If you use Emacs as a daemon (e.g. starting it as `emacs --daemon` or calling `(server-start)`), +you can change the `exec` command to invoke `emacsclient` directly. In this case, no output file +will be written.: + +```json +"custom/org": { + "format": " {}", + "return-type": "json", + "restart-interval": 5, + "exec": "emacsclient --eval '(org-clock-waybar-ouptut-task)'" +} + +``` + +Then, add `custom/org` to `modules-left`/`modules-center`/`module-right` if your bar’s +configuration. You can find a minimal working configuration in the [`examples`](./examples) +directory. ## Customization diff --git a/org-clock-waybar.el b/org-clock-waybar.el index ef084d7..4adf4f2 100644 --- a/org-clock-waybar.el +++ b/org-clock-waybar.el @@ -95,6 +95,14 @@ value of `org-clock-waybar-not-clocked-in-text'." (insert (org-clock-waybar--get-clocked-task-json)) (write-file org-clock-waybar-filename))) +(defun org-clock-waybar-ouptut-task () + "Output the current task in JSON format Waybar can understand. + +This function is ought to be used via Emacsclient: + +emacsclient --eval '(org-clock-waybar-output-task)'" + (print (org-clock-waybar--get-clocked-task-json))) + (defun org-clock-waybar-setup () "Setup org-clock-waybar.