8
8
"fmt"
9
9
"os"
10
10
"os/exec"
11
- "path"
12
11
"runtime"
13
12
"strconv"
14
13
"strings"
@@ -17,6 +16,7 @@ import (
17
16
"github.com/coreos/go-semver/semver"
18
17
"github.com/lima-vm/lima/pkg/instance"
19
18
"github.com/lima-vm/lima/pkg/ioutilx"
19
+ "github.com/lima-vm/lima/pkg/limayaml"
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"
@@ -139,10 +139,10 @@ func shellAction(cmd *cobra.Command, args []string) error {
139
139
if workDir != "" {
140
140
changeDirCmd = fmt .Sprintf ("cd %s || exit 1" , shellescape .Quote (workDir ))
141
141
// FIXME: check whether y.Mounts contains the home, not just len > 0
142
- } else if len (inst .Config .Mounts ) > 0 {
142
+ } else if len (inst .Config .Mounts ) > 0 || inst . VMType == limayaml . WSL2 {
143
143
hostCurrentDir , err := os .Getwd ()
144
144
if err == nil && runtime .GOOS == "windows" {
145
- hostCurrentDir , err = mountDirFromWindowsDir (hostCurrentDir )
145
+ hostCurrentDir , err = mountDirFromWindowsDir (inst , hostCurrentDir )
146
146
}
147
147
if err == nil {
148
148
changeDirCmd = fmt .Sprintf ("cd %s" , shellescape .Quote (hostCurrentDir ))
@@ -152,7 +152,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
152
152
}
153
153
hostHomeDir , err := os .UserHomeDir ()
154
154
if err == nil && runtime .GOOS == "windows" {
155
- hostHomeDir , err = mountDirFromWindowsDir (hostHomeDir )
155
+ hostHomeDir , err = mountDirFromWindowsDir (inst , hostHomeDir )
156
156
}
157
157
if err == nil {
158
158
changeDirCmd = fmt .Sprintf ("%s || cd %s" , changeDirCmd , shellescape .Quote (hostHomeDir ))
@@ -244,12 +244,12 @@ func shellAction(cmd *cobra.Command, args []string) error {
244
244
return sshCmd .Run ()
245
245
}
246
246
247
- func mountDirFromWindowsDir (dir string ) (string , error ) {
248
- dir , err := ioutilx . WindowsSubsystemPath ( dir )
249
- if err == nil && ! strings . HasPrefix ( dir , "/mnt/" ) {
250
- dir = path . Join ( "/mnt" , dir )
247
+ func mountDirFromWindowsDir (inst * store. Instance , dir string ) (string , error ) {
248
+ if inst . VMType == limayaml . WSL2 {
249
+ distroName := "lima-" + inst . Name
250
+ return ioutilx . WindowsSubsystemPathForLinux ( dir , distroName )
251
251
}
252
- return dir , err
252
+ return ioutilx . WindowsSubsystemPath ( dir )
253
253
}
254
254
255
255
func shellBashComplete (cmd * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
0 commit comments