Skip to content

Commit

Permalink
Merge pull request #1 from joehillen/main
Browse files Browse the repository at this point in the history
Major Refactor
  • Loading branch information
JadielTeofilo authored Aug 18, 2021
2 parents 9c175ac + b31d4e5 commit ffdf559
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
29 changes: 14 additions & 15 deletions README.md
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)
14 changes: 0 additions & 14 deletions flip_stopwatch

This file was deleted.

Binary file removed img/example.gif
Binary file not shown.
56 changes: 40 additions & 16 deletions stopwatch
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'

0 comments on commit ffdf559

Please sign in to comment.