Add more config options and a tooltip #1
35
README.md
35
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)`),
|
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
|
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
|
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
|
(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
|
```json
|
||||||
"custom/org": {
|
"custom/org": {
|
||||||
"format": " {}",
|
"format": "{icon} {}",
|
||||||
"return-type": "json",
|
"return-type": "json",
|
||||||
"restart-interval": 5,
|
"restart-interval": 1,
|
||||||
"exec": "emacsclient --eval '(org-clock-waybar-ouptut-task)' | jq fromjson"
|
"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)'",
|
||||||
|
},
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -64,6 +64,15 @@
|
|||||||
'emacs-mule)
|
'emacs-mule)
|
||||||
"Coding system of the file `org-clock-waybar-filename'.")
|
"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)
|
(defun org-clock-waybar--get-clocked-task-json (&optional clocking-out)
|
||||||
"Get the currently clocked-in task’s data as a stringified JSON object.
|
"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))
|
(let* ((task (if clocking-out nil org-clock-current-task))
|
||||||
(category (when task (get-text-property 0 'org-category task)))
|
(category (when task (get-text-property 0 'org-category task)))
|
||||||
(title (when task (substring-no-properties task)))
|
(title (when task (substring-no-properties task)))
|
||||||
|
(tooltip (org-clock-waybar-tooltip))
|
||||||
(output (json-new-object)))
|
(output (json-new-object)))
|
||||||
(setq output (json-add-to-object
|
(setq output (json-add-to-object
|
||||||
output
|
output
|
||||||
@ -85,7 +95,7 @@ before setting `org-clock-current-task' to nil."
|
|||||||
title
|
title
|
||||||
org-clock-waybar-not-clocked-in-text)))
|
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 "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 "class" ""))
|
||||||
(setq output (json-add-to-object output "percentage" ""))
|
(setq output (json-add-to-object output "percentage" ""))
|
||||||
(json-encode output)))
|
(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?