From d5025d4057fa11a5549b8b2597d55ae24034db81 Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Sun, 12 Feb 2023 17:59:49 -0800 Subject: [PATCH] :sparkles: Added pomo script and basic docker-sh --- scripts/docker-sh | 2 + scripts/pomo | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100755 scripts/docker-sh create mode 100755 scripts/pomo diff --git a/scripts/docker-sh b/scripts/docker-sh new file mode 100755 index 00000000..0723a3be --- /dev/null +++ b/scripts/docker-sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +docker exec -it "${1}" bash diff --git a/scripts/pomo b/scripts/pomo new file mode 100755 index 00000000..492f66d9 --- /dev/null +++ b/scripts/pomo @@ -0,0 +1,135 @@ +#!/bin/bash + +# Basic pomodoro timer written in bash using dunst +# https://github.com/Prayag2/pomo/blob/main/pomo + +# DEFAULT VALUES +ICON="xclock" +NAME="Simple Pomodoro" + +FOCUS=1500 +BREAK=300 +LONG_BREAK=1200 +ROUNDS=4 +CYCLES=1 + +FOCUS_SCRIPT="" +BREAK_SCRIPT="" +LBREAK_SCRIPT="" +EXIT_SCRIPT="" + +HELP="Simple Pomodoro Timer! +Options: +\t-f +\t-b +\t-l +\t-r +\t-c +\t-F +\t-B +\t-L +\t-E " + + +# PARSE OPTIONS +while getopts "f:b:r:c:l:F:B:L:E:h" opt; do + case $opt in + f) + FOCUS=$OPTARG ;; + b) + BREAK=$OPTARG ;; + r) + ROUNDS=$OPTARG ;; + c) + CYCLES=$OPTARG ;; + l) + LONG_BREAK=$OPTARG ;; + F) + FOCUS_SCRIPT=$OPTARG ;; + B) + BREAK_SCRIPT=$OPTARG ;; + L) + LBREAK_SCRIPT=$OPTARG ;; + E) + EXIT_SCRIPT=$OPTARG ;; + h|\?) + printf "$HELP\n" + exit 1 ;; + esac +done + + +formatTime() { + if [[ $2 -eq 1 ]]; then + printf '%02d' $(expr $1) + else + printf '%02d' $(expr $1 - 1) + fi +} + +timer() { + MIN=$(expr $1 / 60) + SEC=$(expr $1 - $MIN \* 60) + + for (( min=$MIN; min>=0; min-- )) + do + for (( sec=$SEC; sec>0; sec-- )) + do + BODY="Time Remaining: $(formatTime $min 1):$(formatTime $sec) seconds" + OUTPUT=$(timeout 1 notify-send "$2" "$BODY" -r $3 -u low -a "$NAME" -i "$ICON" -A "Pause" -A "Stop" & sleep 1) + case $OUTPUT in + 0) + notify-send "Paused!" "$BODY" -r $3 -u critical -a "$NAME" -i "$ICON" -A "Resume" + ;; + 1) + quit + ;; + esac + done + SEC=60 + done + +} + +start() { + NOTI=$(notify-send "Pomodoro Session Started!" -p) + sh -c "$FOCUS_SCRIPT" + timer $FOCUS "Cycle $1 • Session $2 • Focus Time!" $NOTI + + if [[ $3 -eq 1 ]]; then + notify-send "LONG BREAK TIME!" -r $NOTI + sh -c "$LBREAK_SCRIPT" + timer $LONG_BREAK "Long Break!" $NOTI + + elif [[ $3 -eq 2 ]]; then + return; + + else + notify-send "BREAK TIME!" -r $NOTI + sh -c "$BREAK_SCRIPT" + timer $BREAK "Short Break!" $NOTI + fi + +} + +quit() { + sh -c "$EXIT_SCRIPT" + exit 0 +} + +trap quit SIGINT +for (( i=0; i<$CYCLES; i++ )) +do + for (( j=1; j<=$ROUNDS; j++ )) + do + k=$(expr $i + 1) + if [[ j -eq $ROUNDS ]] && [[ i -ne $(expr $CYCLES - 1) ]]; then + start $k $j 1 + elif [[ j -eq $ROUNDS ]] && [[ i -eq $(expr $CYCLES - 1) ]]; then + start $k $j 2 + else + start $k $j + fi + done +done +quit