WSL icon indicating copy to clipboard operation
WSL copied to clipboard

"Bash Here" Context Menu in Windows Explorer

Open Manouchehri opened this issue 10 years ago • 26 comments

We should have a context menu that gives an option to open Bash in the current folder.

image

Manouchehri avatar Jun 30 '16 06:06 Manouchehri

I have already written a reg file if anyone wants to add it now.

https://github.com/Manouchehri/bash-WSL-context-menu

Manouchehri avatar Jun 30 '16 06:06 Manouchehri

image

Manouchehri avatar Jun 30 '16 06:06 Manouchehri

Thanks, this is great! One change you should consider making though is remove the hardcoded C:\Windows portion of the path which will only work for user's who have C:\Windows as their Windows directory. You can fix this by using a REG_EXPAND_SZ registry value. Here's what bash.reg would look like:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\WSL]
@="Bash"
"Icon"="%USERPROFILE%\\AppData\\Local\\lxss\\bash.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\WSL\command]
@=hex(2):22,00,25,00,57,00,49,00,4e,00,44,00,49,00,52,00,25,00,5c,00,\
  53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,62,00,61,00,73,00,68,\
  00,2e,00,65,00,78,00,65,00,22,00,00,00

benhillis avatar Jun 30 '16 15:06 benhillis

Pull requests are always appreciated. 😊 Sorry, I haven't used Windows since the 7 Technical Preview so I've forgotten with how directories/paths work here.

Feel free to add this to LxRun.exe or wherever is appropriate, would be convenient to have it set up by default.

Manouchehri avatar Jun 30 '16 15:06 Manouchehri

Also there's no need to write to HKCR. If you really do want it to be available for all users, write to HKLM\Software\Classes. If you only want it to apply to the current user, write to HKCU\Software\Classes.

factormystic avatar Jun 30 '16 15:06 factormystic

The reason I wrote it in HKCR is because cmd and Git Bash both did that.

We should probably installing it per user for WSL, right?

Manouchehri avatar Jun 30 '16 17:06 Manouchehri

Yeah, seems like it should be per-user.

fpqc avatar Jun 30 '16 18:06 fpqc

@benhillis Any update on this?

Manouchehri avatar Jul 11 '16 07:07 Manouchehri

Unfortunately this change will not be in the Windows 10 anniversary update. Thanks for providing the reg key, I think many users will want this functionality and luckily it is easy to achieve with a simple reg key import.

benhillis avatar Jul 11 '16 15:07 benhillis

Thanks, good to know. =)

Manouchehri avatar Jul 11 '16 18:07 Manouchehri

Thanks for the reg key! Any word on this being incorporated into future updates?

JamesEarle avatar Aug 03 '16 16:08 JamesEarle

Yeah, please get this incorporated ASAP. Because the other windows directories are mounted in mnt it makes it to where you cant just easily copy and paste paths from explorer. So, this is the quickest way to quickly open up the current explorer directory you are viewing, in bash.

TimothyBramlett avatar Aug 06 '16 19:08 TimothyBramlett

TimothyBramlett I bet @xilun could add something to cbwin like "wcd" that would do patht translation back from Windows paths to linux ones.

fpqc avatar Aug 06 '16 20:08 fpqc

@fpqc It's quite easy to program but a little bit out of scope on my side... also you would have to single quote escape it due to backslashes - not very convenient. I think ConEmu does path translation on paste, but then of course when you use ConEmu and WSL at the moment there is the current issue of WSL / console keys not working well outside of an unwrapped Windows Console.

xilun avatar Aug 06 '16 20:08 xilun

I'm always getting "/mnt/c/Windows/System32", how can I get "current directory"?

saschanaz avatar Oct 24 '16 13:10 saschanaz

Please use ConEmu instead, it's much better than my method.

On Oct 24, 2016 9:02 AM, "Kagami Sascha Rosylight" [email protected] wrote:

I'm always getting "/mnt/c/Windows/System32", how can I get "current directory"?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BashOnWindows/issues/603#issuecomment-255733847, or mute the thread https://github.com/notifications/unsubscribe-auth/AG5col3dYQgrIs9BdGM0joDJ36UE3vNrks5q3KxngaJpZM4JB1_P .

Manouchehri avatar Oct 25 '16 18:10 Manouchehri

One of the reasons we can't support file explorer context menu extensions is because we can't launch bash at an arbitrary folder location.

We have it on our backlog to fix for a future release.

bitcrazed avatar Feb 21 '17 23:02 bitcrazed

Here's a working solution that uses an aux. cmd command to change to the target directory first, which therefore comes with a caveat: the resulting Bash console window will therefore have cmd.exe's icon and will be grouped with regular cmd.exe in the taskbar.

If you save the following text in a *.reg file and open (double-click) it, you'll be prompted to import the definitions into your user-specific registry hive.

After import, you'll find a Bash Console Here command in the context menu of folders in File Explorer, and also when you click in the empty space inside a folder.
On selecting that command, a Bash console window will open in that folder.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\BashConsoleHere]
@="Bash Console Here"
"Icon"=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,\
  00,54,00,41,00,25,00,5c,00,6c,00,78,00,73,00,73,00,5c,00,62,00,61,00,73,00,\
  68,00,2e,00,69,00,63,00,6f,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\BashConsoleHere\command]
@="cmd /c cd \"%V\" && bash.exe"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\BashConsoleHere]
@="Bash Console Here"
"Icon"=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,\
  00,54,00,41,00,25,00,5c,00,6c,00,78,00,73,00,73,00,5c,00,62,00,61,00,73,00,\
  68,00,2e,00,69,00,63,00,6f,00,00,00

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\BashConsoleHere\command]
@="cmd /c cd \"%1\" && bash.exe"

Alternatively, you can use the following PowerShell snippet to create the registry entries:

$null = 0..1 | % {
  $key = New-Item -Force $('HKCU:\Software\Classes\Directory{0}\shell\BashConsoleHere' -f ('', '\Background')[$_])
  $key | New-ItemProperty -Name '(Default)' -Value 'Bash Console Here' -Type String
  $key | New-ItemProperty -Name 'Icon' -Value '%LOCALAPPDATA%\lxss\bash.ico' -Type ExpandString
  $key = New-Item -Force "$($key.PsPath)\command"
  $key | New-ItemProperty -Name '(Default)' -Value "cmd /c cd `"$(('%1', '%V')[$_])`" && bash.exe" -Type String
}

To remove the entries later:

0..1 | % {
  Remove-Item -Recurse -LiteralPath $('HKCU:\Software\Classes\Directory{0}\shell\BashConsoleHere' -f ('', '\Background')[$_])
}

mklement0 avatar Feb 27 '17 04:02 mklement0

This works great and all, but at this point definitely seems like a feature that should be an option to have baked in. Any ideas on if there are plans for that?

Tetheta avatar Oct 17 '17 15:10 Tetheta

Any news on that issue?

SplittyDev avatar Apr 06 '18 12:04 SplittyDev