Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Bash Here" Context Menu in Windows Explorer #603

Closed
Manouchehri opened this issue Jun 30, 2016 · 26 comments
Closed

"Bash Here" Context Menu in Windows Explorer #603

Manouchehri opened this issue Jun 30, 2016 · 26 comments
Assignees
Labels

Comments

@Manouchehri
Copy link
Contributor

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

image

@Manouchehri
Copy link
Contributor Author

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

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

@Manouchehri
Copy link
Contributor Author

image

@benhillis
Copy link
Member

benhillis commented Jun 30, 2016

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

@Manouchehri
Copy link
Contributor Author

Manouchehri commented Jun 30, 2016 via email

@factormystic
Copy link

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.

@Manouchehri
Copy link
Contributor Author

Manouchehri commented Jun 30, 2016 via email

@fpqc
Copy link

fpqc commented Jun 30, 2016

Yeah, seems like it should be per-user.

@Manouchehri
Copy link
Contributor Author

@benhillis Any update on this?

@benhillis
Copy link
Member

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.

@Manouchehri
Copy link
Contributor Author

Manouchehri commented Jul 11, 2016 via email

@JamesEarle
Copy link

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

@TimothyBramlett
Copy link

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.

@fpqc
Copy link

fpqc commented Aug 6, 2016

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

@xilun
Copy link

xilun commented Aug 6, 2016

@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.

@saschanaz
Copy link

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

@Manouchehri
Copy link
Contributor Author

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

On Oct 24, 2016 9:02 AM, "Kagami Sascha Rosylight" notifications@github.com
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
#603 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AG5col3dYQgrIs9BdGM0joDJ36UE3vNrks5q3KxngaJpZM4JB1_P
.

@bitcrazed bitcrazed self-assigned this Feb 21, 2017
@bitcrazed
Copy link
Contributor

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.

@mklement0
Copy link

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')[$_])
}

@Tetheta
Copy link

Tetheta commented Oct 17, 2017

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?

@SplittyDev
Copy link

Any news on that issue?

@Brian-Perkins
Copy link

Support for a context menu item was added in build 17666.

@mkarpoff
Copy link

Something I've noticed is that if you use the open bash here context menu. It doesn't use any of your wsl console settings (eg. colors, fonts, window and font size)

@sunilmut
Copy link
Member

@bitcrazed - Could @mkarpoff's report be console related?

@fpqc
Copy link

fpqc commented Jun 1, 2018

@sunilmut without a doubt it is console-related.

@bitcrazed
Copy link
Contributor

@mkarpoff As described in our post explaining how Console settings are resolved, when you launch a distro via Explorer context menu, the Console will look for settings in the following locations and order:

  1. Launching shortcut (none in this case)
  2. App-specific settings in the Registry
  3. Default Console settings in the Registry

As noted above, when you launch via the context menu, you're not launching via a tile, so Console will look for distro settings, or default Console settings from the registry.

If you launch your distro from a start menu tile, or shortcut pinned to your taskbar, your Console settings for that distro will be stored in that tile/shortcut but won't be found/used when launching via the context menu.

Alas, we can't change this behavior in Console as it stands today, because doing so would break MANY users' expected behaviors, etc.

However, we are looking at how we might rationalize, simplify, and improve settings in the future.

@eromoe
Copy link

eromoe commented Apr 22, 2019

@Brian-Perkins Could you consider adding an icon ?
shift context menu would show powershell and linux shell
image

This would look ugly with some menu-items had icon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests