Skip to content

Commit 2674cbc

Browse files
committed
feat: provide read from stdin
1 parent 4f8250a commit 2674cbc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

cmd/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package main
1616

1717
import (
18+
"bufio"
1819
"fmt"
1920
"os"
2021
"path/filepath"
@@ -52,6 +53,32 @@ var (
5253
os.Exit(1)
5354
}
5455

56+
stat, _ := os.Stdin.Stat()
57+
if (stat.Mode() & os.ModeCharDevice) == 0 {
58+
f, err := os.CreateTemp("", "tmpfile-")
59+
if err != nil {
60+
log.Fatal(err)
61+
}
62+
63+
// close and remove the temporary file at the end of the program
64+
defer f.Close()
65+
defer os.Remove(f.Name())
66+
67+
// write data to the temporary file
68+
reader := bufio.NewScanner(os.Stdin)
69+
for reader.Scan() {
70+
text := reader.Text()
71+
if _, err := f.WriteString(text); err != nil {
72+
log.Fatal(err)
73+
}
74+
}
75+
76+
sshConfigFile = f.Name()
77+
if err != nil {
78+
log.Fatal(err)
79+
}
80+
}
81+
5582
if sshConfigFile == "" {
5683
sshConfigFile = filepath.Join(home, ".ssh", "config")
5784
}

internal/core/services/server_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (s *serverService) SetPinned(alias string, pinned bool) error {
156156
// SSH starts an interactive SSH session to the given alias using the system's ssh client.
157157
func (s *serverService) SSH(alias string) error {
158158
s.logger.Infow("ssh start", "alias", alias)
159-
cmd := exec.Command("ssh", alias)
159+
cmd := exec.Command("ssh", "-tt", alias)
160160
cmd.Stdin = os.Stdin
161161
cmd.Stdout = os.Stdout
162162
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)