commit 892a94309f36d4e8cbfa03f6746f71e63fe5af56 parent 5fec5dc983a6d1dc399fcdb74346fbf3ba6986ef Author: pyratebeard <root@pyratebeard.net> Date: Wed, 6 Oct 2021 15:35:49 +0100 tmux interpolate file and timer script Diffstat:
A | golden_apple.tmux | | | 34 | ++++++++++++++++++++++++++++++++++ |
A | scripts/timer.sh | | | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/golden_apple.tmux b/golden_apple.tmux @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +timer="#($CURRENT_DIR/scripts/timer.sh)" +interpolate_string="\#{goldenapple}" + +interpolate() { + local -r status="$1" + local -r status_value=$(tmux show-option -gqv "$status") + tmux set-option -gq "$status" "${status_value/$interpolate_string/$timer}" +} + +timer() { + interpolate "status-left" + interpolate "status-right" +} + +killtimer() { + for p in $(ps -ef | grep $CURRENT_DIR/scripts/timer.sh | grep -v grep | awk '{print $2}') ; do + kill -9 $p + done + tmux source-file ~/.tmux.conf >/dev/null 2>&1 +} + +main() { + tmux source-file ~/.tmux.conf >/dev/null 2>&1 + case $1 in + start) timer ;; + stop) killtimer ; exit 0 ;; + esac +} + +main $1 diff --git a/scripts/timer.sh b/scripts/timer.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +work=15 +work_option="@work" + +get_tmux_option() { + local -r option="$1" + local -r default_option="$2" + local -r option_value="$(tmux show-option -gqv "$option")" + if [ -z "$option_value" ] ; then + echo "$default_option" + else + echo "$option_value" + fi +} + +pomodoro_timer() { + echo $$ >> /tmp/goldenapple.pid + echo "running" > /tmp/goldenapple.status + + IFS=: + set -- $* + secs=$(( ${1#0} * 60 + 00 )) + while [ $secs -gt 0 ] + do + sleep 1 & + printf "\r %02d:%02d " $(( (secs/60)%60)) $((secs%60)) + secs=$(( $secs - 1 )) + wait + done + echo + for p in $(ps -ef | grep $CURRENT_DIR/scripts/timer.sh | grep -v grep | awk '{print $2}') ; do + kill -9 $p + done + tmux source-file ~/.tmux.conf >/dev/null 2>&1 + tmux display-popup -w 30% -h 8% echo "pomodoro work period done" +} + +main() { + local -r work_count="$(get_tmux_option "$work_option" "$work")" + pomodoro_timer ${work_count} +} + +main