feat: add session autocompletions

This commit is contained in:
2026-01-30 01:35:39 +02:00
parent 9cad6b2cef
commit 2e741464c1
4 changed files with 41 additions and 15 deletions

View File

@@ -10,11 +10,12 @@ import (
)
var attachCmd = &cobra.Command{
Use: "attach [key]",
Aliases: []string{"a"},
Short: "Attach to a tmux session",
Args: cobra.MaximumNArgs(1),
RunE: runAttach,
Use: "attach [key]",
Aliases: []string{"a"},
Short: "Attach to a tmux session",
Args: cobra.MaximumNArgs(1),
RunE: runAttach,
ValidArgsFunction: completeSessionNames,
}
func runAttach(cmd *cobra.Command, args []string) error {

View File

@@ -11,11 +11,12 @@ import (
var removeLocal bool
var removeCmd = &cobra.Command{
Use: "remove <key>",
Aliases: []string{"rm"},
Short: "Remove a tmux workspace from the config file",
Args: cobra.ExactArgs(1),
RunE: runRemove,
Use: "remove <key>",
Aliases: []string{"rm"},
Short: "Remove a tmux workspace from the config file",
Args: cobra.ExactArgs(1),
RunE: runRemove,
ValidArgsFunction: completeSessionNames,
}
func init() {

View File

@@ -52,6 +52,29 @@ It supports complex pane layouts, fzf selection, and config merging.`,
RunE: runMain,
SilenceErrors: true, // We handle error printing in Execute()
SilenceUsage: true, // Don't print usage on runtime errors
ValidArgsFunction: completeSessionNames,
}
// completeSessionNames returns session names for shell completion
func completeSessionNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// Don't complete if we already have an argument
if len(args) > 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
cfg, err := config.GetTmuxConfig()
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
var names []string
for name := range cfg {
if name != config.ConfigKey {
names = append(names, name)
}
}
return names, cobra.ShellCompDirectiveNoFileComp
}
// initConfig loads global configuration and applies settings

View File

@@ -12,11 +12,12 @@ import (
var showJSON bool
var showCmd = &cobra.Command{
Use: "show [key]",
Aliases: []string{"s"},
Short: "Show the tmux configuration for a specific key",
Args: cobra.MaximumNArgs(1),
RunE: runShow,
Use: "show [key]",
Aliases: []string{"s"},
Short: "Show the tmux configuration for a specific key",
Args: cobra.MaximumNArgs(1),
RunE: runShow,
ValidArgsFunction: completeSessionNames,
}
func init() {