|
| 1 | +# waybar-timer |
| 2 | + |
| 3 | +This script implements a **simple** and **customizable** timer for your bar. |
| 4 | + |
| 5 | +- specify a command to execute when the timer expires (e.g. notify-send, shell script, ...) |
| 6 | +- interactive: |
| 7 | + * e.g. scroll to increase / decrease timer |
| 8 | + * click to start predefined timers |
| 9 | + * while changing a timer a notification displays when the timer will expire |
| 10 | + * pause timer |
| 11 | + |
| 12 | + (set a timer) |
| 13 | + |
| 14 | + (cancel a timer) |
| 15 | + |
| 16 | + (start predefined timer) |
| 17 | + |
| 18 | + (start other predefined timer and increase it) |
| 19 | + |
| 20 | + (watch expiry time when you change a timer) |
| 21 | + |
| 22 | +Even though the repo is named [`waybar-timer`](#), it is a general script and you can use it for every bar. |
| 23 | +In particular, if you use [**polybar**](https://github.com/polybar/polybar), then you can find a polybar-specific implementation of this timer [here](https://github.com/jbirnick/polybar-timer). |
| 24 | +You can **customize behaviour and appearance in a simple way**. |
| 25 | + |
| 26 | +Use cases: pomodoro timer, self-reminder when next meeting begins, tea/pasta timer, ... |
| 27 | + |
| 28 | +## Dependencies |
| 29 | + |
| 30 | +Inside the script `dunstify` is called to view the mentioned notification for the expiry time. |
| 31 | +But this is not necessary. (Just beautiful.) If you do not use Dunst then you need to edit two lines in the script according to [this issue](https://github.com/jbirnick/polybar-timer/issues/3), and still everything (but the preview of the expiry time) **will work fine without dependencies**. |
| 32 | + |
| 33 | +## Installation |
| 34 | + |
| 35 | +1. Download [waybar-timer.sh](https://raw.githubusercontent.com/jbirnick/waybar-timer/master/waybar-timer.sh) from this repo. |
| 36 | +2. Make it executable. (`chmod +x waybar-timer.sh`) |
| 37 | +3. Copy-paste the [example configuration](#example-configuration) from below into your waybar config and style it. |
| 38 | +4. Customize. (see [Customization section](#customization)) |
| 39 | + |
| 40 | +## Example Configuration |
| 41 | + |
| 42 | +```json |
| 43 | +"custom/timer": { |
| 44 | + "exec": "/path/to/waybar-timer.sh updateandprint", |
| 45 | + "exec-on-event": true, |
| 46 | + "return-type": "json", |
| 47 | + "interval": 5, |
| 48 | + "signal": 4, |
| 49 | + "format": "{icon} {}", |
| 50 | + "format-icons": { |
| 51 | + "standby": "STANDBY", |
| 52 | + "running": "RUNNING", |
| 53 | + "paused": "PAUSE" |
| 54 | + }, |
| 55 | + "on-click": "/path/to/waybar-timer.sh new 25 'notify-send \"Session finished\"'", |
| 56 | + "on-click-middle": "/path/to/waybar-timer.sh cancel", |
| 57 | + "on-click-right": "/path/to/waybar-timer.sh togglepause", |
| 58 | + "on-scroll-up": "/path/to/waybar-timer.sh increase 60 || /path/to/waybar-timer.sh new 1 'notify-send -u critical \"Timer expired.\"'", |
| 59 | + "on-scroll-down": "/path/to/waybar-timer.sh increase -60" |
| 60 | +} |
| 61 | +``` |
| 62 | +The first modification you probably want to make is to replace the `format-icons` by some actually stylish icons. |
| 63 | + |
| 64 | +Furthermore you can style the module using the `timer` class, for example: |
| 65 | +``` |
| 66 | +.timer { |
| 67 | + background-color: #ffee82; |
| 68 | + color: #242424; |
| 69 | + margin: 0 10px; |
| 70 | + padding: 0 10px; |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +## Customization |
| 75 | + |
| 76 | +The example configuration implements a 25min "pomodoro session" timer with left click, pausing with right click, canceling with middle click, and a normal timer by just scrolling up from the standby mode. |
| 77 | + |
| 78 | +You can customize the different strings, numbers and actions to your own flavor and needs. To understand what the commands do and to implement some different behaviour see the [documentation](#documentation). |
| 79 | + |
| 80 | +If you want to do some really specific stuff and add some functionality, just edit the script. It is really simple. Just take your 10 minutes to understand what it does and then customize it. |
| 81 | + |
| 82 | +## Documentation |
| 83 | + |
| 84 | +Notation: `<...>` are necessary arguments. `[...=DEFAULTVALUE]` are optional arguments, |
| 85 | +and if you do not specify them their `DEFAULTVALUE` is used. |
| 86 | + |
| 87 | +If want to understand or edit the script, I highly recommend to run a *tail process* (see below) in a terminal window without any bar. |
| 88 | +This way you will see what the bar sees |
| 89 | +and you will understand how the updates work. |
| 90 | + |
| 91 | +The main command of the script is: |
| 92 | + |
| 93 | +- #### `updateandprint` |
| 94 | + This routine will return the current the output (i.e. what you see on the bar) and handle the `ACTION` if the timer expired. |
| 95 | + Namely: |
| 96 | + 1. If there is a timer running and its expiry time is <= now, then it executes `ACTION` and kills the timer. |
| 97 | + 2. It prints the output info for waybar, in particular the number of remaining minutes. |
| 98 | + |
| 99 | +Now the following commands allow you to control the timer. |
| 100 | + |
| 101 | +- #### `new <MINUTES> [ACTION=""]` |
| 102 | + 1. If there is a timer already running this timer gets killed. |
| 103 | + 2. Creates a timer of length `MINUTES` minutes and sets its action to `ACTION`. (`ACTION` will be executed once the timer expires.) |
| 104 | + |
| 105 | +- #### `increase <SECONDS>` |
| 106 | + If there is no timer set, nothing happens and it exits with 1. |
| 107 | + If there is a timer set, it is extended by `SECONDS` seconds. `SECONDS` can also be negative, in which case it shortens the timer. Then it exits |
| 108 | + with 0. |
| 109 | + |
| 110 | +- #### `togglepause` |
| 111 | + If there is no timer set at all, it exits with 1. If there is a timer running, the timer gets paused and it exits with 0. If there is a timer set which is already paused, the timer gets resumed and it exits with 0. |
| 112 | + |
| 113 | +- #### `cancel` |
| 114 | + If there is a timer running, the timer gets canceled. The `ACTION` will _not_ be |
| 115 | + executed. |
| 116 | + |
| 117 | +## Tips & Tricks |
| 118 | + |
| 119 | +Note, when there is no timer active, then [`increase`](#increase-seconds) does nothing. |
| 120 | +So you might want to use the following command as a replacement for [`increase`](#increase-seconds). |
| 121 | +``` |
| 122 | +waybar-timer.sh increase 60 || waybar-timer.sh new 1 'mytimer' 'notify-send "Timer expired."' |
| 123 | +``` |
| 124 | +It increases the existing timer if it's active, and creates a timer with label |
| 125 | +"mytimer" of lengths 1 minute if there is no timer currently running. |
| 126 | +So now e.g. scrolling up also does something when there is no timer active - it starts a new timer! |
| 127 | + |
| 128 | +## Known Issues |
| 129 | + |
| 130 | +If you don't (want to) use `dunstify` please see the [dependencies section](#dependencies). |
0 commit comments