-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from joehillen/main
Major Refactor
- Loading branch information
Showing
4 changed files
with
54 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
# i3blocks-stop-watch | ||
A very simple stopwatch timer for i3 blocks | ||
|
||
A simple stopwatch timer for i3blocks | ||
|
||
### Installing | ||
# Usage | ||
|
||
Start/stop the stopwatch by left-clicking on the block. | ||
|
||
- Add scripts stopwatch and flip_stopwach to the path. Eg.: | ||
Reset it by right-clicking on the block. | ||
|
||
### Installing | ||
|
||
``` | ||
sudo cp stopwatch /usr/bin | ||
sudo cp flip_stopwatch /usr/bin | ||
``` | ||
|
||
- Add the following to the i3blocks.conf: | ||
|
||
``` | ||
# Stopwatch thing | ||
# Stopwatch | ||
[stopwatch] | ||
label=⏱ | ||
interval=1 | ||
command=stopwatch | ||
separator=true | ||
#label= | ||
``` | ||
|
||
And to the i3 config, add a shortcut to flip the stopwatch state: | ||
- If desired keybindings can be added to i3 to control the stopwatch, for example: | ||
|
||
``` | ||
bindsym mod1+t exec flip_stopwatch | ||
# Start/Stop stopwatch | ||
bindsym Pause exec env BLOCK_BUTTON=1 stopwatch | ||
# Reset stopwatch | ||
bindsym Shift+Pause exec env BLOCK_BUTTON=3 stopwatch | ||
``` | ||
|
||
On my config `mod1` is `alt`, so I can start and stop the timer with `alt+t`. | ||
|
||
Example: | ||
|
||
![Alt Text](img/example.gif) |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
#!/bin/bash | ||
|
||
DIR=/dev/shm/i3blocks-stop-watch | ||
mkdir -p "$DIR" | ||
|
||
function update_date() | ||
{ | ||
STATUS_FILE=$DIR/status | ||
touch $STATUS_FILE | ||
: "${STATUS:=$(<$STATUS_FILE)}" "${STATUS:=reset}" | ||
|
||
start_date=`date +%s`; | ||
echo $start_date > /tmp/stopwatch_start.date | ||
START_FILE=$DIR/start | ||
touch $START_FILE | ||
: "${START:=$(<$START_FILE)}" "${START:=$(date +%s)}" | ||
|
||
} | ||
STOP_FILE=$DIR/stop | ||
touch $STOP_FILE | ||
: "${STOP:=$(<$STOP_FILE)}" "${STOP:=$(date +%s)}" | ||
|
||
|
||
function main() | ||
{ | ||
if [ $(</tmp/stopwatch_is_on) = 'true' ] | ||
then | ||
echo "$(date -u --date @$((`date +%s` - $(</tmp/stopwatch_start.date))) +%H:%M:%S)"; | ||
if [[ $BLOCK_BUTTON = 1 ]]; then | ||
# start/stop on left-click | ||
if [[ $STATUS = running ]]; then | ||
STATUS=stopped | ||
date +%s >$STOP_FILE | ||
else | ||
update_date | ||
echo false > /tmp/stopwatch_is_on; | ||
echo '' | ||
STATUS=running | ||
CUR=$(date +%s) | ||
START=$((CUR - STOP + START)) | ||
echo "$START" >$START_FILE | ||
STOP=$CUR | ||
echo "$STOP" >$STOP_FILE | ||
fi | ||
} | ||
elif [[ $BLOCK_BUTTON = 3 ]]; then | ||
# reset on right-click | ||
STATUS=reset | ||
fi | ||
|
||
echo $STATUS >$STATUS_FILE | ||
|
||
if [[ $STATUS = reset ]]; then | ||
echo >$START_FILE | ||
echo >$STOP_FILE | ||
exit 0 | ||
fi | ||
|
||
if [[ $STATUS = running ]]; then | ||
STOP=$(date +%s) | ||
echo "$STOP" >$STOP_FILE | ||
fi | ||
|
||
main | ||
date -u --date=@$((STOP - START)) '+%H:%M:%S' |