@@ -20,6 +20,7 @@ import (
20
20
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
21
21
"github.com/lima-vm/lima/pkg/sshutil"
22
22
"github.com/lima-vm/lima/pkg/store"
23
+ "github.com/lima-vm/sshocker/pkg/ssh"
23
24
"github.com/mattn/go-isatty"
24
25
"github.com/sirupsen/logrus"
25
26
"github.com/spf13/cobra"
@@ -51,6 +52,7 @@ func newShellCommand() *cobra.Command {
51
52
52
53
shellCmd .Flags ().String ("shell" , "" , "shell interpreter, e.g. /bin/bash" )
53
54
shellCmd .Flags ().String ("workdir" , "" , "working directory" )
55
+ shellCmd .Flags ().Bool ("reconnect" , false , "reconnect to the SSH session" )
54
56
return shellCmd
55
57
}
56
58
@@ -107,6 +109,24 @@ func shellAction(cmd *cobra.Command, args []string) error {
107
109
}
108
110
}
109
111
112
+ restart , err := cmd .Flags ().GetBool ("reconnect" )
113
+ if err != nil {
114
+ return err
115
+ }
116
+ if restart {
117
+ logrus .Infof ("Exiting ssh session for the instance %q" , instName )
118
+
119
+ sshConfig := & ssh.SSHConfig {
120
+ ConfigFile : inst .SSHConfigFile ,
121
+ Persist : false ,
122
+ AdditionalArgs : []string {},
123
+ }
124
+
125
+ if err := ssh .ExitMaster (inst .Hostname , inst .SSHLocalPort , sshConfig ); err != nil {
126
+ return err
127
+ }
128
+ }
129
+
110
130
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
111
131
//
112
132
// changeDirCmd := "cd workDir || exit 1" if workDir != ""
0 commit comments