@@ -8,14 +8,14 @@ import (
88 "fmt"
99 "os"
1010 "os/exec"
11- "path"
1211 "runtime"
1312 "strconv"
1413 "strings"
1514
1615 "al.essio.dev/pkg/shellescape"
1716 "github.com/coreos/go-semver/semver"
1817 "github.com/lima-vm/lima/pkg/ioutilx"
18+ "github.com/lima-vm/lima/pkg/limayaml"
1919 "github.com/lima-vm/lima/pkg/sshutil"
2020 "github.com/lima-vm/lima/pkg/store"
2121 "github.com/mattn/go-isatty"
@@ -93,10 +93,10 @@ func shellAction(cmd *cobra.Command, args []string) error {
9393 if workDir != "" {
9494 changeDirCmd = fmt .Sprintf ("cd %s || exit 1" , shellescape .Quote (workDir ))
9595 // FIXME: check whether y.Mounts contains the home, not just len > 0
96- } else if len (inst .Config .Mounts ) > 0 {
96+ } else if len (inst .Config .Mounts ) > 0 || inst . VMType == limayaml . WSL2 {
9797 hostCurrentDir , err := os .Getwd ()
9898 if err == nil && runtime .GOOS == "windows" {
99- hostCurrentDir , err = mountDirFromWindowsDir (hostCurrentDir )
99+ hostCurrentDir , err = mountDirFromWindowsDir (inst , hostCurrentDir )
100100 }
101101 if err == nil {
102102 changeDirCmd = fmt .Sprintf ("cd %s" , shellescape .Quote (hostCurrentDir ))
@@ -106,7 +106,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
106106 }
107107 hostHomeDir , err := os .UserHomeDir ()
108108 if err == nil && runtime .GOOS == "windows" {
109- hostHomeDir , err = mountDirFromWindowsDir (hostHomeDir )
109+ hostHomeDir , err = mountDirFromWindowsDir (inst , hostHomeDir )
110110 }
111111 if err == nil {
112112 changeDirCmd = fmt .Sprintf ("%s || cd %s" , changeDirCmd , shellescape .Quote (hostHomeDir ))
@@ -198,12 +198,12 @@ func shellAction(cmd *cobra.Command, args []string) error {
198198 return sshCmd .Run ()
199199}
200200
201- func mountDirFromWindowsDir (dir string ) (string , error ) {
202- dir , err := ioutilx . WindowsSubsystemPath ( dir )
203- if err == nil && ! strings . HasPrefix ( dir , "/mnt/" ) {
204- dir = path . Join ( "/mnt" , dir )
201+ func mountDirFromWindowsDir (inst * store. Instance , dir string ) (string , error ) {
202+ if inst . VMType == limayaml . WSL2 {
203+ distroName := "lima-" + inst . Name
204+ return ioutilx . WindowsSubsystemPathForLinux ( dir , distroName )
205205 }
206- return dir , err
206+ return ioutilx . WindowsSubsystemPath ( dir )
207207}
208208
209209func shellBashComplete (cmd * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
0 commit comments