From 92f896af054ee148a685376581d2035119b34341 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Thu, 11 Mar 2021 15:50:47 +0000 Subject: [PATCH 1/2] Add more config options and a tooltip --- README.md | 35 +++++++++++++++++++++++++++++------ org-clock-waybar.el | 12 +++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 71a735d..a391123 100644 --- a/README.md +++ b/README.md @@ -23,19 +23,42 @@ To add the current task to Waybar, add this snippet to your config: } ``` +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`. In this case, no output file will be written.: +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": " {}", - "return-type": "json", - "restart-interval": 5, - "exec": "emacsclient --eval '(org-clock-waybar-ouptut-task)' | jq fromjson" -} + "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)'", +}, ``` 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))) -- 2.45.2 From bc61218f922337e70c379b05d3b61ceba54b34a5 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Thu, 11 Mar 2021 11:22:45 +0000 Subject: [PATCH 2/2] A bash script for catching when the server is offline --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a391123..4973baf 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ 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. + +### Additional Configuration + You can also display an icon specific to the clocked tasks category with the `format-icons` key: ```json @@ -62,9 +68,15 @@ If you run emacs in this mode you can also eval commands on click, middle click ``` -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 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 -- 2.45.2