2021-03-11 04:58:49 +00:00
# org-clock-waybar – Export the currently clocked-in task to be displayed on Waybar
## Installation
Put `org-clock-waybar.el` somewhere in your `load-path` , and `(require 'org-clock-waybar)` .
MELPA version may come soon.
2021-03-11 05:14:54 +00:00
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.)
2021-03-11 04:58:49 +00:00
2021-03-12 16:52:38 +00:00
### Quelpa
If you only have [`quelpa` ](https://github.com/quelpa/quelpa ) installed:
```elisp
(quelpa
'(org-clock-waybar
:fetcher git
:url "https://gitea.polonkai.eu/gergely/org-clock-waybar.git"))
```
or, if you have [`quelpa-use-package` ](https://github.com/quelpa/quelpa-use-package ) installed,
too:
```elisp
(quelpa-use-package org-clock-waybar
:quelpa (org-clock-waybar
:fetcher git
:url "https://gitea.polonkai.eu/gergely/org-clock-waybar.git"))
```
2021-03-11 04:58:49 +00:00
## Waybar configuration
To add the current task to Waybar, add this snippet to your config:
2021-03-11 05:14:54 +00:00
```json
2021-03-11 04:58:49 +00:00
"custom/org": {
"format": " {}",
"return-type": "json",
"restart-interval": 5,
"exec": "cat /home/yourusername/.cache/waybar-current-task.json"
}
```
2021-03-11 11:22:45 +00:00
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.
### Additional Configuration
2021-03-11 15:50:47 +00:00
You can also display an icon specific to the clocked tasks category with the `format-icons` key:
```json
"custom/org": {
"format": "{icon} {}",
"return-type": "json",
"restart-interval": 1,
"format-icons": {
"refile": "",
"ToDo": "",
},
"exec": "cat /home/yourusername/.cache/waybar-current-task.json"
}
```
2021-03-11 05:14:54 +00:00
If you use Emacs as a daemon (e.g. starting it as `emacs --daemon` or calling `(server-start)` ),
2021-03-11 06:21:13 +00:00
you can change the `exec` command to invoke `emacsclient` directly. Note that, since Emacsclient
can’ t actually write stuff to the terminal, it will output an Emacs string full of backslashes
(see [this Emacs SE answer for details ](https://emacs.stackexchange.com/a/28668/507 )); thus, you
2021-03-11 15:50:47 +00:00
have to pipe the output through `jq fromjson` .
If you run emacs in this mode you can also eval commands on click, middle click or scroll.:
2021-03-11 05:14:54 +00:00
```json
"custom/org": {
2021-03-11 15:50:47 +00:00
"format": "{icon} {}",
"return-type": "json",
"restart-interval": 1,
"format-icons": {
"refile": "",
"ToDo": "",
},
"exec": "emacsclient --eval '(org-clock-waybar-ouptut-task)' | jq fromjson --unbuffered --compact-output",
"on-click": "emacsclient --eval '(org-clock-out)'",
"on-middle-click": "emacsclient --eval '(org-clock-in-last)'",
},
2021-03-11 05:14:54 +00:00
```
2021-03-11 11:22:45 +00:00
If you want the taskbar to show nothing or some other content if the emacs server is not running then you need to write a short bash script to catch when the emacsclient command returns a non-zero exit code. An example of this is:
```bash
#!/bin/bash
json=$(emacsclient --eval '(org-clock-waybar-ouptut-task)' 2> /dev/null)
status=$?
[ $status -eq 0 ] & & echo $(echo $json | jq fromjson --unbuffered --compact-output) || echo ""
```
2021-03-11 05:14:48 +00:00
## Customization
To see a list of configurable parts, use `M-x customize-group <RET> org-clock-waybar` .