Add more config options and a tooltip #1
67
README.md
67
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 <RET> org-clock-waybar`.
|
||||
|
@ -64,6 +64,15 @@
|
||||
'emacs-mule)
|
||||
"Coding system of the file `org-clock-waybar-filename'.")
|
||||
|
||||
(defun org-clock-waybar-tooltip ()
|
||||
Cadair
commented
I split these into functions so they can be overriden if people want to customise the content? Is this the best way to achieve that? I split these into functions so they can be overriden if people want to customise the content? Is this the best way to achieve that?
gergely
commented
Yeah, i’d probably make that actually customizable, like have these as
Later we might add new symbols here, obviously. Thus, users can do something like this:
Also (on the longer run), these values might get a function as a value, which should return a string, so users can customize stuff to the deepest depths 😄 Yeah, i’d probably make that *actually customizable*, like have these as `defcustom` variables, each of which can have symbols as values:
- `'title` means the task’s title
- `'category` means the task’s category
- `'clock-in-time` means the clock in time
- `'clocked-time` means the time since clocking in
Later we might add new symbols here, obviously.
Thus, users can do something like this:
```
(setq org-clock-waybar-text 'title)
(setq org-clock-waybar-alt 'category)
(setq org-clock-waybar-tooltip 'clocked-time)
```
Also (on the longer run), these values might get a function as a value, which should return a string, so users can customize stuff to the deepest depths 😄
Cadair
commented
Can you compose multiple of those things together into one line though? So you could have the tooltip be Can you compose multiple of those things together into one line though? So you could have the tooltip be `"category: [clock-in-time] title (clocked-time)"` or something?
|
||||
"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)))
|
||||
|
Loading…
Reference in New Issue
Block a user
A file will still be written?
No, if you call
(org-clock-waybar-output-task)
, the JSON file won’t be written (well, not unless you explicitly addedorg-clock-waybar-save-task
toorg-clock-in-hook
; the two are completely independent from each other).But requiring this file adds the hooks no? So while calling this function doesn't write the file, the hooks are already in place?