diff options
| -rw-r--r-- | README.md | 21 | ||||
| -rw-r--r-- | cmd/timr/main.go | 4 | ||||
| -rw-r--r-- | integrations/fish-shell/completions/timr.fish | 7 | ||||
| -rw-r--r-- | integrations/fish-shell/functions/timr_prompt.fish | 17 | ||||
| -rw-r--r-- | internal/timer/operations.go | 25 |
5 files changed, 72 insertions, 2 deletions
@@ -29,3 +29,24 @@ sudo mv timr /usr/local/bin/ * `timr status`: Shows the current status of the timer (running or stopped) and the total elapsed time. * `timr reset`: Resets the timer. This will set the elapsed time to zero. * `timr live`: Shows a live, full-screen timer with keyboard controls (q: quit, s: start/stop, r: reset). + +## Fish Shell Integration + +`timr` can be integrated with the fish shell to display the current timer status in your prompt. + +### Installation + +1. Copy the `integrations/fish-shell` directory to your fish plugins directory: + + ```bash + cp -r integrations/fish-shell ~/.config/fish/plugins/timr + ``` + +2. Update your `fish_prompt` or `fish_right_prompt` function to include the `timr_prompt` function. For example, you can add the following to your `~/.config/fish/functions/fish_prompt.fish` file: + + ```fish + function fish_prompt + # ... your existing prompt ... + printf ' %s' (timr_prompt) + end + ``` diff --git a/cmd/timr/main.go b/cmd/timr/main.go index 534275b..0625070 100644 --- a/cmd/timr/main.go +++ b/cmd/timr/main.go @@ -27,6 +27,8 @@ func main() { output, err = timer.GetStatus() case "reset": output, err = timer.ResetTimer() + case "prompt": + output, err = timer.GetPromptStatus() case "live": p := tea.NewProgram(live.NewModel()) if err := p.Start(); err != nil { @@ -47,5 +49,5 @@ func main() { } func printUsage() { - fmt.Println("Usage: timr <start|stop|pause|status|reset|live>") + fmt.Println("Usage: timr <start|stop|pause|status|reset|live|prompt>") } diff --git a/integrations/fish-shell/completions/timr.fish b/integrations/fish-shell/completions/timr.fish new file mode 100644 index 0000000..b71ad60 --- /dev/null +++ b/integrations/fish-shell/completions/timr.fish @@ -0,0 +1,7 @@ +complete -c timr -n "__fish_use_subcommand" -a start -d "Start the timer" +complete -c timr -n "__fish_use_subcommand" -a stop -d "Stop the timer" +complete -c timr -n "__fish_use_subcommand" -a pause -d "Pause the timer" +complete -c timr -n "__fish_use_subcommand" -a status -d "Show the timer status" +complete -c timr -n "__fish_use_subcommand" -a reset -d "Reset the timer" +complete -c timr -n "__fish_use_subcommand" -a live -d "Show the live timer" +complete -c timr -n "__fish_use_subcommand" -a prompt -d "Show the prompt status" diff --git a/integrations/fish-shell/functions/timr_prompt.fish b/integrations/fish-shell/functions/timr_prompt.fish new file mode 100644 index 0000000..fe17bf1 --- /dev/null +++ b/integrations/fish-shell/functions/timr_prompt.fish @@ -0,0 +1,17 @@ +function timr_prompt -d "Display timr status in the prompt" + if command -v timr >/dev/null + set -l status (timr prompt) + if test -n "$status" + set -l icon (string sub -l 1 -- "$status") + set -l time (string sub -s 2 -- "$status") + if test "$icon" = "▶" + set_color green + else + set_color yellow + end + printf '%s' "$icon" + set_color normal + printf ' %s' "$time" + end + end +end diff --git a/internal/timer/operations.go b/internal/timer/operations.go index 3035b58..71cf684 100644 --- a/internal/timer/operations.go +++ b/internal/timer/operations.go @@ -72,4 +72,27 @@ func ResetTimer() (string, error) { return "", fmt.Errorf("error saving state: %w", err) } return "Timer reset.", nil -}
\ No newline at end of file +} + +func GetPromptStatus() (string, error) { + state, err := LoadState() + if err != nil { + return "", fmt.Errorf("error loading state: %w", err) + } + + elapsed := state.ElapsedTime + if state.Running { + elapsed += time.Since(state.StartTime) + } + + if elapsed == 0 { + return "", nil + } + + icon := "⏸" + if state.Running { + icon = "▶" + } + + return fmt.Sprintf("%s %s", icon, elapsed.Round(time.Second)), nil +} |
