mirror of
https://github.com/chenasraf/tx.git
synced 2026-05-17 17:28:08 +00:00
feat: add session autocompletions
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user