Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ set -g @pomodoro_sound 'off' # Sound for desktop notifications

set -g @pomodoro_notifications 'off' # Enable desktop notifications from your terminal
set -g @pomodoro_granularity 'off' # Enables MM:SS (ex: 00:10) format instead of the default (ex: 1m)

set -g @pomodoro_on_complete_cmd "" # Custom command to run when a Pomodoro completes
set -g @pomodoro_on_break_end_cmd "" # Custom command to run when a break ends
set -g @pomodoro_on_long_break_end_cmd "" # Custom command to run when a long break ends
```

### Customising the status line
Expand Down
21 changes: 21 additions & 0 deletions scripts/pomodoro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pomodoro_notifications="@pomodoro_notifications"
pomodoro_granularity="@pomodoro_granularity"
pomodoro_disable_breaks="@pomodoro_disable_breaks"

pomodoro_on_complete_cmd="@pomodoro_on_complete_cmd"
pomodoro_on_break_end_cmd="@pomodoro_on_break_end_cmd"
pomodoro_on_long_break_end_cmd="@pomodoro_on_long_break_end_cmd"

# ______________________________________________________________| methods |__ ;

source "$CURRENT_DIR/helpers.sh"
Expand Down Expand Up @@ -76,6 +80,15 @@ get_pomodoro_disable_breaks() {
get_tmux_option "$pomodoro_disable_breaks" "off"
}

run_custom_cmd() {
local option="$1"
local cmd
cmd=$(get_tmux_option "$option" "")
if [ -n "$cmd" ]; then
eval "$cmd" &
fi
}

get_seconds() {
date +%s
}
Expand Down Expand Up @@ -449,6 +462,7 @@ pomodoro_status() {
if [ "$pomodoro_completed" = true ] && [ "$pomodoro_status" == "in_progress" ] && [ "$disable_breaks" != "on" ]; then
pomodoro_status="break"
remove_time_paused_file
run_custom_cmd "$pomodoro_on_complete_cmd"

if prompt_user; then
pomodoro_status="waiting_for_break"
Expand All @@ -469,6 +483,7 @@ pomodoro_status() {
# Breaks are disabled
if [ "$pomodoro_completed" = true ] && [ "$pomodoro_status" == "in_progress" ] && [ "$disable_breaks" == "on" ]; then
remove_time_paused_file
run_custom_cmd "$pomodoro_on_complete_cmd"

if prompt_user; then
set_status "waiting_for_pomodoro"
Expand Down Expand Up @@ -504,6 +519,12 @@ pomodoro_status() {
if [ "$break_complete" = true ] && { [ "$pomodoro_status" == "break" ] || [ "$pomodoro_status" == "long_break" ]; }; then
remove_time_paused_file

if [ "$pomodoro_status" == "long_break" ]; then
run_custom_cmd "$pomodoro_on_long_break_end_cmd"
else
run_custom_cmd "$pomodoro_on_break_end_cmd"
fi

if prompt_user; then
set_status "waiting_for_pomodoro"
send_notification "🍅 Break completed!" "Start the Pomodoro?" true
Expand Down
26 changes: 26 additions & 0 deletions tests/pomodoro_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ test_pomodoro_can_be_stopped() {

assertEquals 1 $status
}

test_run_custom_cmd_executes_command() {
local test_file="/tmp/pomodoro/test_custom_cmd.txt"
rm -f "$test_file"

tmux set -g @pomodoro_test_cmd "echo 'hello' > $test_file"
run_custom_cmd "@pomodoro_test_cmd"
sleep 1

file_exists "$test_file"
local status=$?
assertEquals 0 $status

local content
content=$(cat "$test_file")
assertEquals "hello" "$content"

rm -f "$test_file"
}

test_run_custom_cmd_does_nothing_when_empty() {
# Should not error when the option is unset/empty
run_custom_cmd "@pomodoro_nonexistent_option"
local status=$?
assertEquals 0 $status
}
###############################################################################

# run the tests
Expand Down