88 "fmt"
99 "os"
1010 "os/exec"
11- "path"
1211 "runtime"
1312 "strconv"
1413 "strings"
@@ -17,6 +16,7 @@ import (
1716 "github.com/coreos/go-semver/semver"
1817 "github.com/lima-vm/lima/pkg/instance"
1918 "github.com/lima-vm/lima/pkg/ioutilx"
19+ "github.com/lima-vm/lima/pkg/limayaml"
2020 networks "github.com/lima-vm/lima/pkg/networks/reconcile"
2121 "github.com/lima-vm/lima/pkg/sshutil"
2222 "github.com/lima-vm/lima/pkg/store"
@@ -139,10 +139,10 @@ func shellAction(cmd *cobra.Command, args []string) error {
139139 if workDir != "" {
140140 changeDirCmd = fmt .Sprintf ("cd %s || exit 1" , shellescape .Quote (workDir ))
141141 // 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 {
143143 hostCurrentDir , err := os .Getwd ()
144144 if err == nil && runtime .GOOS == "windows" {
145- hostCurrentDir , err = mountDirFromWindowsDir (hostCurrentDir )
145+ hostCurrentDir , err = mountDirFromWindowsDir (inst , hostCurrentDir )
146146 }
147147 if err == nil {
148148 changeDirCmd = fmt .Sprintf ("cd %s" , shellescape .Quote (hostCurrentDir ))
@@ -152,7 +152,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
152152 }
153153 hostHomeDir , err := os .UserHomeDir ()
154154 if err == nil && runtime .GOOS == "windows" {
155- hostHomeDir , err = mountDirFromWindowsDir (hostHomeDir )
155+ hostHomeDir , err = mountDirFromWindowsDir (inst , hostHomeDir )
156156 }
157157 if err == nil {
158158 changeDirCmd = fmt .Sprintf ("%s || cd %s" , changeDirCmd , shellescape .Quote (hostHomeDir ))
@@ -244,12 +244,12 @@ func shellAction(cmd *cobra.Command, args []string) error {
244244 return sshCmd .Run ()
245245}
246246
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 )
251251 }
252- return dir , err
252+ return ioutilx . WindowsSubsystemPath ( dir )
253253}
254254
255255func shellBashComplete (cmd * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
0 commit comments