Skip to content

Commit

Permalink
Change tmux-color to take custom colors
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Jan 18, 2021
1 parent c40c0bd commit 7041748
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [Take a break](#take-a-break)
* [Repeat the last Pomodoro](#repeat-the-last-pomodoro)
* [Show Pomodoro history](#show-pomodoro-history)
* [Tmux Color](#tmux-color)
* [Status Format](#status-format)
* [Available Parts](#available-parts)
* [Hooks](#hooks)
Expand Down Expand Up @@ -183,6 +184,34 @@ $ pomodoro history --output json
$ pomodoro history --output ical > ~/Pomodoros.ics
```

### Tmux Color

`tmux-color` returns a color for the current Pomodoro status.

```
# Active Pomodoro
$ pomodoro tmux-color
colour2 # Green
# Finished Pomodoro
$ pomodoro tmux-color
colour1 # Red
```

Nothing is output if no Pomodoro is active.

You can also define custom colors:

```
# Active Pomodoro
$ pomodoro tmux-color --active colour166 --done colour165
colour166 # Orange
# Finished Pomodoro
$ pomodoro tmux-color --active colour166 --done colour165
colour165 # Purple
```

## Status Format

All commands which display the status of a single Pomodoro can take an additional `--format` / `-f` argument.
Expand Down
24 changes: 17 additions & 7 deletions cmd/tmux_color.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@ import (
"github.com/spf13/cobra"
)

const (
tmuxRed = "colour1"
tmuxGreen = "colour2"
var (
activeFlag string
doneFlag string
)

func init() {
RootCmd.AddCommand(&cobra.Command{
command := &cobra.Command{
Use: "tmux-color",
Short: "Return a tmux color string for the status.",
RunE: tmuxColorCmd,
})
}

command.Flags().StringVarP(
&activeFlag, "active", "a", "colour2",
"color when a Pomodoro is active")

command.Flags().StringVarP(
&doneFlag, "done", "d", "colour1",
"color when a Pomodoro is done")

RootCmd.AddCommand(command)
}

func tmuxColorCmd(cmd *cobra.Command, args []string) error {
Expand All @@ -26,11 +36,11 @@ func tmuxColorCmd(cmd *cobra.Command, args []string) error {
}

if s.Pomodoro.IsActive() {
fmt.Printf(tmuxGreen)
fmt.Printf(activeFlag)
}

if s.Pomodoro.IsDone() {
fmt.Printf(tmuxRed)
fmt.Printf(doneFlag)
}

return nil
Expand Down

0 comments on commit 7041748

Please sign in to comment.