Implemented basic system

This commit is contained in:
2018-04-02 15:40:10 +01:00
parent 080d61728c
commit 3a482ca3f7
11 changed files with 135 additions and 30 deletions

20
main.go
View File

@@ -23,6 +23,7 @@ import (
"os"
"os/user"
"strings"
"os/exec"
)
type host struct {
@@ -94,11 +95,12 @@ func main() {
return strings.Contains(name, input)
}
hostTemplate := "{{\"[\" | bold}}{{.Name | cyan | bold }}{{\"]\" | bold}} {{ .User |bold }} @ {{ .HostName | bold }}"
templates := &promptui.SelectTemplates{
Label: "{{ . }}",
Active: ">{{ .User | cyan }}@({{ .HostName | red }})",
Inactive: " {{ .User | cyan }}@({{ .HostName | red }})",
Selected: "{{ .User | cyan }}@({{ .HostName | red }})",
Active: fmt.Sprintf(">%s", hostTemplate),
Inactive: fmt.Sprintf(" %s", hostTemplate),
Selected: "{{\"Connecting to\"|bold}} {{.Name|cyan|bold}}",
}
prompt := promptui.Select{
@@ -109,12 +111,16 @@ func main() {
Searcher: searcher,
}
i, _, err := prompt.Run()
i, _, promptErr := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
if promptErr != nil {
fmt.Print("No option selected")
return
}
fmt.Printf("You choose number %d: %s\n", i+1, hosts[i].Name)
cmd := exec.Command("ssh", hosts[i].Name)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}