Skip to content

Periodically write state file for external integration#28

Open
vizcay wants to merge 1 commit into
Bahaaio:mainfrom
vizcay:write-state-file
Open

Periodically write state file for external integration#28
vizcay wants to merge 1 commit into
Bahaaio:mainfrom
vizcay:write-state-file

Conversation

@vizcay

@vizcay vizcay commented Jun 19, 2026

Copy link
Copy Markdown

This feature, when the new WriteStateFile config is enabled, will write periodically a /tmp/pomo.json file updating the current state of the application:

 {
  "state": "running",
  "type": "work",
  "elapsed_seconds": 312,
  "duration_seconds": 1500,
  "remaining_seconds": 1188,
  "sessions_done": 1,
  "cycle_position": 2
}

This is ideal if you want to read the state from some utility, in my scenario a tmux statusbar, which allows me to see my curent pomodoro session without the need to switch to it:

Usage example

Screenshot 2026-06-19 at 23 11 24
#!/usr/bin/env bash

STATE_FILE="/tmp/pomo.json"

if [ ! -f "$STATE_FILE" ]; then
  echo ""
  exit 0
fi

format_time() {
  local s=$1
  printf "%02d:%02d" $((s / 60)) $((s % 60))
}

elapsed=$(jq -r '.elapsed_seconds' "$STATE_FILE")
duration=$(jq -r '.duration_seconds' "$STATE_FILE")
percent=$(jq -r '(.percent * 100 | floor)' "$STATE_FILE")
state=$(jq -r '.state' "$STATE_FILE")
type=$(jq -r '.type' "$STATE_FILE")

if [ "$type" = "break" ]; then
  prefix="󰅶 "
else
  prefix=""
  [ "$state" = "running" ] && prefix=""
  [ "$state" = "paused" ] && prefix=""
  [ "$state" = "completed" ] && prefix=""
fi

elapsed_min=$(( (elapsed + 30) / 60 ))
duration_min=$(( (duration + 30) / 60 ))

echo "${prefix}$(format_time "$elapsed") ${duration_min}min ${percent}%"

@vizcay vizcay changed the title Periodically write state file if enabled to integrate Periodically write state file for external integration Jun 19, 2026
@Bahaaio

Bahaaio commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Good idea!
I had actually planned something similar already, but never had the time to implement it.

That said, I think a better approach would be a simple HTTP server that serves a string or JSON on demand rather than constantly writing to a file. Then a sub-command could act as the client, something like pomo status, possibly also pomo status --json.

This could also make it possible to support actions like pause/resume from the client side later on.

One more thing: using a hardcoded path like /tmp would break cross-platform compatibility.

@TotoCodeFR

Copy link
Copy Markdown

Would love this feature.

I use the pomo CLI quite a lot, and I wanted to be able to show the time left on a micro:bit 4 digit display.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants