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