diff --git a/config/parser.go b/config/parser.go index b30b52f3..f02b6397 100644 --- a/config/parser.go +++ b/config/parser.go @@ -28,6 +28,8 @@ var validate *validator.Validate type ViewType string +type KeyList []string + const ( PRsView ViewType = "prs" IssuesView ViewType = "issues" @@ -111,7 +113,7 @@ type RepoConfig struct { } type Keybinding struct { - Key string `yaml:"key"` + Key KeyList `yaml:"key"` Command string `yaml:"command"` Builtin string `yaml:"builtin"` } @@ -123,8 +125,8 @@ func (kb Keybinding) NewBinding(previous *key.Binding) key.Binding { } return key.NewBinding( - key.WithKeys(kb.Key), - key.WithHelp(kb.Key, helpDesc), + key.WithKeys(kb.Key...), + key.WithHelp(strings.Join(kb.Key, "/"), helpDesc), ) } @@ -486,3 +488,22 @@ func ParseConfig(path string, repoPath *string) (Config, error) { return config, nil } + +func (kl *KeyList) UnmarshalYAML(unmarshal func(interface{}) error) error { + // Try unmarshaling into a []string first + var list []string + if err := unmarshal(&list); err == nil { + *kl = list + return nil + } + + // If that fails, try unmarshaling into a single string + var single string + if err := unmarshal(&single); err == nil { + *kl = []string{single} + return nil + } + + // If both attempts fail, return an error + return fmt.Errorf("key must be either a string or a list of strings") +}