diff --git a/README.md b/README.md index 71a735d..4973baf 100644 --- a/README.md +++ b/README.md @@ -23,26 +23,61 @@ To add the current task to Waybar, add this snippet to your config: } ``` -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. 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 -have to pipe the output through `jq fromjson`. 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)' | jq fromjson" -} - -``` - 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 + +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" +} +``` + +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. 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 +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.: + +```json +"custom/org": { + "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)'", +}, + +``` + +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 "" +``` + ## Customization To see a list of configurable parts, use `M-x customize-group org-clock-waybar`. diff --git a/org-clock-waybar.el b/org-clock-waybar.el index 8cc97a5..1d2bfac 100644 --- a/org-clock-waybar.el +++ b/org-clock-waybar.el @@ -64,6 +64,15 @@ 'emacs-mule) "Coding system of the file `org-clock-waybar-filename'.") +(defun org-clock-waybar-tooltip () + "The default tooltip to send to waybar." + (when org-clock-current-task + (let ((clocked-time (org-clock-get-clocked-time))) + (format "%s: %s (%s)" + (org-clock-waybar-alt) + (org-clock-waybar-text) + (org-duration-from-minutes clocked-time))))) + (defun org-clock-waybar--get-clocked-task-json (&optional clocking-out) "Get the currently clocked-in task’s data as a stringified JSON object. @@ -77,6 +86,7 @@ before setting `org-clock-current-task' to nil." (let* ((task (if clocking-out nil org-clock-current-task)) (category (when task (get-text-property 0 'org-category task))) (title (when task (substring-no-properties task))) + (tooltip (org-clock-waybar-tooltip)) (output (json-new-object))) (setq output (json-add-to-object output @@ -85,7 +95,7 @@ before setting `org-clock-current-task' to nil." title org-clock-waybar-not-clocked-in-text))) (setq output (json-add-to-object output "alt" (if category category ""))) - (setq output (json-add-to-object output "tooltip" "")) + (setq output (json-add-to-object output "tooltip" (if tooltip tooltip ""))) (setq output (json-add-to-object output "class" "")) (setq output (json-add-to-object output "percentage" "")) (json-encode output)))