From 913d2f10bbe6b2b61a1140409e96c2f1b0bd8ed0 Mon Sep 17 00:00:00 2001 From: Saahil Bhavsar Date: Thu, 25 Jul 2024 22:26:37 +0530 Subject: [PATCH] Adds option to run the selected alias command Signed-off-by: Saahil Bhavsar --- cli/cmd/alias/list.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/cmd/alias/list.go b/cli/cmd/alias/list.go index b7ec19a..9f7027a 100644 --- a/cli/cmd/alias/list.go +++ b/cli/cmd/alias/list.go @@ -3,6 +3,8 @@ package alias import ( "fmt" "os" + "os/exec" + "strings" "github.com/devlup-labs/spok/internal/pkg/selector" "github.com/spf13/cobra" @@ -32,10 +34,21 @@ var listCmd = &cobra.Command{ choice := menu.Display() menu.Clear() - fmt.Println(choice) + if run, _ := cmd.Flags().GetBool("run"); run { + sshCommand := strings.Split(choice, " ") + + cmd := exec.Command(sshCommand[0], sshCommand[1:]...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cobra.CheckErr(cmd.Run()) + } else { + fmt.Println(choice) + } }, } func init() { + listCmd.Flags().BoolP("run", "r", false, "Run the selected alias") AliasCmd.AddCommand(listCmd) }