diff options
| -rw-r--r-- | LICENSE.md | 18 | ||||
| -rw-r--r-- | README.md | 33 | ||||
| -rwxr-xr-x | listimer | 58 |
3 files changed, 109 insertions, 0 deletions
diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8c0c4fe --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,18 @@ +Copyright (c) 2026 Clément Sibille + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c0b83e2 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# Listimer + +Simple timer meant to be displayed in a sway-bar status. + +## Usage + +Start the timer with the `start` subcommand. + +```sh +$ listimer start <number of minutes> +``` + +Restart the timer with the `restart` subcommand. + +```sh +$ listimer restart +``` + +Stop the timer with the `stop` subcommand. + +```sh +$ listimer stop +``` + +Query the timer with the `query` subcommand. + +```sh +$ listimer query +``` + +The command will output [pango +markup](https://docs.gtk.org/Pango/pango_markup.html). To use it with sway-bar +be sure to enable the `pango_markup` sway-bar option. diff --git a/listimer b/listimer new file mode 100755 index 0000000..fe5f4c3 --- /dev/null +++ b/listimer @@ -0,0 +1,58 @@ +#!/bin/sh + +COMMAND=$1 +case "$COMMAND" +in + "start") + if [ "$#" -ne 2 ]; then + echo "Usage: listimer start <minutes>"; + exit 1; + fi + DURATION_MIN=$2 + CURRENT_TIME=$(date +%s) + echo "$CURRENT_TIME\n\n$DURATION_MIN" > /tmp/listimer + ;; + + "restart") + if [ "$#" -ne 1 ]; then + echo "Usage: listimer restart"; + exit 1; + fi + CURRENT_TIME=$(date +%s) + sed -i "1s/.*/$CURRENT_TIME/" /tmp/listimer + ;; + + "stop") + if [ "$#" -ne 1 ]; then + echo "Usage: listimer stop"; + exit 1; + fi + CURRENT_TIME=$(date +%s) + rm /tmp/listimer + ;; + + "query") + if [ ! -f /tmp/listimer ]; then + echo "No timer" + exit 0; + fi + + START_TIME=$(sed -n '1p' < /tmp/listimer) + DURATION_MIN=$(sed -n '3p' < /tmp/listimer) + DURATION_SEC=$DURATION_MIN*60 + CURRENT_TIME=$(date +%s) + + ELAPSED_TIME_SEC=$(($CURRENT_TIME-$START_TIME)) + ELAPSED_TIME_MIN=$(($ELAPSED_TIME_SEC/60)) + REMAINING_TIME_MIN=$(($DURATION_MIN-$ELAPSED_TIME_MIN)) + + if [ "$REMAINING_TIME_MIN" -lt "$(($DURATION_MIN / 2))" ]; then + echo "<span weight=\"bold\" size=\"larger\" background=\"#FF0000\">$REMAINING_TIME_MIN minutes</span>" + elif [ "$REMAINING_TIME_MIN" -lt "0" ]; then + echo "TIME OUT!" + else + echo "$REMAINING_TIME_MIN minutes" + fi + ;; + *) echo "Unexpected command." +esac |
