aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-03-12 10:19:24 +0100
committerlonkaars <loek@pipeframe.xyz>2024-03-12 10:19:24 +0100
commit501dd5505d950d89f5b4d0ad8249c38c36a102da (patch)
treeababe6702dbdcc19467167c8043cd7d2a5a12fcb /core
parentd3b396b17602ad71a62cbc2eaf595a1d94579c4a (diff)
replace hard-coded breaks with plugin
Diffstat (limited to 'core')
-rw-r--r--core/config10
-rwxr-xr-xcore/lap17
-rw-r--r--core/lib1
-rw-r--r--core/update12
4 files changed, 25 insertions, 15 deletions
diff --git a/core/config b/core/config
deleted file mode 100644
index aedd4f3..0000000
--- a/core/config
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# initialize default configuration values
-export POMODORO_STATE_PATH="${POMODORO_STATE_PATH:-$XDG_CACHE_HOME/$progname}" # ~/.cache/dppt
-export POMODORO_NORMAL_DURATION="${POMODORO_NORMAL_DURATION:-$(( 25 * 60 ))}" # 25 minutes
-export POMODORO_BREAK_SHORT_DURATION="${POMODORO_BREAK_SHORT_DURATION:-$(( 5 * 60 ))}" # 5 minutes
-export POMODORO_BREAK_LONG_DURATION="${POMODORO_BREAK_LONG_DURATION:-$(( 15 * 60 ))}" # 15 minutes
-export POMODORO_BREAK_SHORT_INTERVAL="${POMODORO_BREAK_INTERVAL:-2}" # every other lap
-export POMODORO_BREAK_LONG_INTERVAL="${POMODORO_BREAK_INTERVAL:-6}" # every 3rd break
-
diff --git a/core/lap b/core/lap
new file mode 100755
index 0000000..3c51c0c
--- /dev/null
+++ b/core/lap
@@ -0,0 +1,17 @@
+#!/bin/sh
+[ "$1" = "info" ] && echo "calculate lap duration" && exit 2
+
+lap="$1"
+break_rule() {
+ break_interval=$1
+ break_duration=$2
+ if [ $(( $lap % $break_interval )) -eq $(( $break_interval - 1 )) ] ; then
+ echo $break_duration
+ exit 0
+ fi
+}
+
+break_rule 6 $(( 15 * 60 )) # every 6th lap (every 3rd break) is a 15 minute break
+break_rule 2 $(( 5 * 60 )) # every 2nd lap is a 5 minute break
+echo $(( 25 * 60 )) # every other lap is a normal 25 minute lap
+
diff --git a/core/lib b/core/lib
index 21c64f9..873226c 100644
--- a/core/lib
+++ b/core/lib
@@ -1,6 +1,7 @@
#!/bin/sh
# utility variables and functions
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" # XDG basedir specification
+export POMODORO_STATE_PATH="${POMODORO_STATE_PATH:-$XDG_CACHE_HOME/$progname}" # ~/.cache/dppt
# this variable grows automatically as long as this file is included in each
# subcommand
diff --git a/core/update b/core/update
index fbe0e86..8787754 100644
--- a/core/update
+++ b/core/update
@@ -1,4 +1,5 @@
#!/bin/sh
+[ "$skip_libraries" ] && return
export now="$(date +%s.%N)"
# load current state
@@ -42,10 +43,9 @@ fi
[ "$time" = "0.0" ] && update_time=1
if [ $update_time -eq 1 ] ; then
- time="$POMODORO_NORMAL_DURATION"
- [ $(( $lap % $POMODORO_BREAK_SHORT_INTERVAL )) -eq $(( $POMODORO_BREAK_SHORT_INTERVAL - 1 )) ] && time=$POMODORO_BREAK_SHORT_DURATION
- [ $(( $lap % $POMODORO_BREAK_LONG_INTERVAL )) -eq $(( $POMODORO_BREAK_LONG_INTERVAL - 1 )) ] && time=$POMODORO_BREAK_LONG_DURATION
- remaining="$time"
+ # skip_libraries is used to prevent endless loop (see top of this file)
+ time=$(skip_libraries=y "$prog" lap $lap)
+ remaining=$time
fi
save_state() {
@@ -84,6 +84,8 @@ save_state() {
mv "$POMODORO_STATE_PATH/primary/current" "$POMODORO_STATE_PATH"
}
-# export state variables
+# state variables
export lap state time
+# calculated variables
+export remaining