File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 6
6
"log"
7
7
"os"
8
8
"os/exec"
9
+ "runtime"
9
10
10
11
"github.com/charmbracelet/ssh"
11
12
)
@@ -22,22 +23,31 @@ func main() {
22
23
return
23
24
}
24
25
25
- cmd := exec .Command ("powershell.exe" )
26
- cmd .Env = append (os .Environ (), "SSH_TTY=windows-pty" , fmt .Sprintf ("TERM=%s" , pty .Term ))
26
+ name := "bash"
27
+ if runtime .GOOS == "windows" {
28
+ name = "powershell.exe"
29
+ }
30
+ cmd := exec .Command (name )
31
+ cmd .Env = append (os .Environ (), "SSH_TTY=" + pty .Name (), fmt .Sprintf ("TERM=%s" , pty .Term ))
27
32
if err := pty .Start (cmd ); err != nil {
28
33
fmt .Fprintln (s , err .Error ())
29
34
s .Exit (1 )
30
35
return
31
36
}
32
37
33
- // ProcessState gets populated by pty.Start
34
- for {
35
- if cmd . ProcessState != nil {
36
- break
38
+ if runtime . GOOS == "windows" {
39
+ // ProcessState gets populated by pty.Start waiting on the process
40
+ // to exit.
41
+ for cmd . ProcessState != nil {
37
42
}
38
- }
39
43
40
- s .Exit (cmd .ProcessState .ExitCode ())
44
+ s .Exit (cmd .ProcessState .ExitCode ())
45
+ } else {
46
+ if err := cmd .Wait (); err != nil {
47
+ fmt .Fprintln (s , err )
48
+ s .Exit (cmd .ProcessState .ExitCode ())
49
+ }
50
+ }
41
51
})
42
52
43
53
log .Println ("starting ssh server on port 2222..." )
You can’t perform that action at this time.
0 commit comments