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`.
This commit is contained in:
Gergely Polonkai 2021-03-11 06:14:54 +01:00
parent bf9c74666d
commit cf030fa8d5
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 29 additions and 3 deletions

View File

@ -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 bars 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 bars
configuration. You can find a minimal working configuration in the [`examples`](./examples)
directory.
## Customization

View File

@ -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.