cascadium / wsl-windows-toolbar-launcher

Adds linux GUI application menu to a windows toolbar
MIT License
1.21k stars 50 forks source link

Set start in for generated shortcuts #8

Closed zoredache closed 4 years ago

zoredache commented 4 years ago

When I start a terminal I am dropped into /mnt/c/WINDOWS/system32. This happens because Windows will default Start in to be whatever the path is for the program being launched so on my system C:\WINDOWS\system32\wscript.exe. WSL when launched will try to preserve your working directory.

It seems to me that is very unlikely people will want/need a default working directory in the system32 folder.

fquinner commented 4 years ago

Good call - probably best doing this in the windows .bat script before launching wsl.exe

zoredache commented 4 years ago

Well I was thinking more in the shortcut creation.

 def create_shortcut(link_file, executable, arguments=None, comment=None, icon_file=None):
     windows_lnk = get_windows_path_from_wsl_path(link_file)
     powershell_cmd = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile "
     powershell_cmd += "-Command '"
     powershell_cmd += '$ws = New-Object -ComObject WScript.Shell; '
     powershell_cmd += '$s = $ws.CreateShortcut("%s");' % windows_lnk
     powershell_cmd += '$s.TargetPath = "%s";' % executable
     powershell_cmd += '$s.Arguments = "%s";' % arguments.replace('"', '`"')
     powershell_cmd += '$s.Description = "%s";' % comment
+    powershell_cmd += '$s.WorkingDirectory = "%USERPROFILE%";'
     powershell_cmd += '$s.IconLocation = "%s";' % icon_file
     powershell_cmd += '$s.Save()'

BTW, your powershell command might be less complicated if you used the powershell -EncodedCommand. I suspect getting all the escaping right is a bit tricky.

fquinner commented 4 years ago

Ha yeah yeah it's not hard to tell this is about the only line of powershell I have ever written. WIll look about adding it in there it makes sense to me.

Should possibly also consider Path from the .desktop specification - that would just be discarded at the moment (though that would almost definitely make more sense on the .sh side).

fquinner commented 4 years ago

Pushed in a change there to default to %USERPROFILE as above, but to also allow Path from the desktop specification to take precedence.