Skip to content

Commit

Permalink
Adds option to run the selected alias command
Browse files Browse the repository at this point in the history
Signed-off-by: Saahil Bhavsar <saahil_bhavsar@outlook.com>
  • Loading branch information
SaahilNotSahil committed Jul 25, 2024
1 parent 54cbab5 commit 913d2f1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cli/cmd/alias/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package alias
import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/devlup-labs/spok/internal/pkg/selector"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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)
}

0 comments on commit 913d2f1

Please sign in to comment.