tmux-golden-apple

pomodoro timer tmux plugin
git clone git://git.pyratebeard.net/tmux-golden-apple.git
Log | Files | Refs | README | LICENSE

timer.sh (932B)


      1 #!/usr/bin/env bash
      2 
      3 work=15
      4 work_option="@work"
      5 
      6 get_tmux_option() {
      7 	local -r option="${1}"
      8 	local -r default_option="${2}"
      9 	local -r option_value="$(tmux show-option -gqv "${option}")"
     10 	if [ -z "${option_value}" ] ; then
     11 		echo "${default_option}"
     12 	else
     13 		echo "${option_value}"
     14 	fi
     15 }
     16 
     17 pomodoro_timer() {
     18 	echo $$ >> /tmp/goldenapple.pid
     19 	echo "running" > /tmp/goldenapple.status
     20 
     21 	IFS=:
     22 	set -- "$@"
     23 	secs=$(( ${1#0} * 60 + 00 ))
     24 	while [ ${secs} -gt 0 ]
     25 	do
     26 		sleep 1 &
     27 		printf "\r %02d:%02d " $(( ( secs/60 ) % 60 )) $(( secs % 60 ))
     28 		secs=$(( secs - 1 ))
     29 		wait
     30 	done
     31 	echo
     32 	for p in $(pgrep "${CURRENT_DIR}"/scripts/timer.sh | grep -v grep | awk '{print $2}') ; do
     33 		kill -9 "${p}"
     34 	done
     35 	tmux source-file ~/.tmux.conf >/dev/null 2>&1
     36 	tmux display-popup -w 30% -h 8% echo "pomodoro work period done"
     37 }
     38 
     39 main() {
     40 	local -r work_count="$(get_tmux_option "${work_option}" "${work}")"
     41 	pomodoro_timer "${work_count}"
     42 }
     43 
     44 main