Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MSYS2 "Open Here" registry settings
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\open_msys2]
@="Open MSYS2 here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\open_msys2\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/sh -lc 'cd \"$(cygpath \"%V\")\"; exec bash'"
[HKEY_CLASSES_ROOT\Folder\shell\open_msys2]
@="Open MSYS2 here"
[HKEY_CLASSES_ROOT\Folder\shell\open_msys2\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/sh -lc 'cd \"$(cygpath \"%V\")\"; exec bash'"
@magthe

This comment has been minimized.

Copy link
Owner Author

@magthe magthe commented Sep 11, 2014

Use

c:\msys64\usr\bin\mintty.exe /bin/bash -lc 'cd "$(cygpath "%V")"; export CHERE_INVOKING=1; exec bash --login -i'

to get a login shell.

@intsilence

This comment has been minimized.

Copy link

@intsilence intsilence commented May 17, 2015

That is exactly what I want. Thank you !

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented May 19, 2015

I have created a bash_here.bat file and added c:\msys64\bash_here.bat "%V" in regedit.
Content of bash_here.bat:
:
@echo off
set MSYSTEM=MINGW64
set curpath="."
if NOT 'x%1' == 'x' set curpath=%1
start %~dp0usr\bin\mintty.exe -i /mingw64/share/git/git-for-windows.ico -t "MSYS2 Bash Here" -w normal /usr/bin/bash -lc 'cd "$(cygpath %curpath%)"; export CHERE_INVOKING=1; exec bash --login -i'

@ryanpfeeley

This comment has been minimized.

Copy link

@ryanpfeeley ryanpfeeley commented May 28, 2015

Thanks everyone! Two notes for people like me who might lack familiarity with .reg files:

  1. These registry entries assume msys64 is installed directly on the C drive.
  2. To get a login shell, you can use the string exactly as magthe posted in his comment if you use the regedit.exe GUI editor to create or modify the entries. If you use a .reg file, you need to escape both the \ and the " characters as magthe did in the original post. Therefore the .reg file lines become:
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/bash -lc 'cd \"$(cygpath \"%V\")\"; export CHERE_INVOKING=1; exec bash --login -i'"
@lianera

This comment has been minimized.

Copy link

@lianera lianera commented Feb 27, 2016

Here is a solution for mingw64 with .reg file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_mingw64]
@="Open mingw64 here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_mingw64\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/sh -lc 'export MSYSTEM=MINGW64;cd \"$(cygpath \"%V\")\";exec bash --login'"

[HKEY_CLASSES_ROOT\Folder\shell\open_mingw64]
@="Open mingw64 here"

[HKEY_CLASSES_ROOT\Folder\shell\open_mingw64\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/sh -lc 'export MSYSTEM=MINGW64;cd \"$(cygpath \"%V\")\";exec bash --login'"
@MacGyver27

This comment has been minimized.

Copy link

@MacGyver27 MacGyver27 commented Jul 8, 2016

My reg file for all 3 variants..

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw32]
@="MinGW &32 Bash Here"
"Icon"="\"C:\\msys64\\mingw32.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw32\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/bash -lc 'export MSYSTEM=MINGW32; cd \"$(cygpath \"%V\")\"; export CHERE_INVOKING=1; exec bash --login -i'"

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\mingw64.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/bash -lc 'export MSYSTEM=MINGW64; cd \"$(cygpath \"%V\")\"; export CHERE_INVOKING=1; exec bash --login -i'"

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2]
@="MSYS2 Bash Here"
"Icon"="\"C:\\msys64\\msys2.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2\command]
@="c:\\msys64\\usr\\bin\\mintty.exe /bin/bash -lc 'export MSYSTEM=MSYS; cd \"$(cygpath \"%V\")\"; export CHERE_INVOKING=1; exec bash --login -i'"
@coldfix

This comment has been minimized.

Copy link

@coldfix coldfix commented Aug 17, 2016

Substitute %V with %V/ in this solution. Without the slash the command breaks for top level directories (i.e. drives) since %V expands to something like C:\ and the trailing backslash breaks the escaping of the quote.

See my fork for a more fixed version.

@Salamandar

This comment has been minimized.

Copy link

@Salamandar Salamandar commented Feb 9, 2017

Hmmm, I got a way simpler solution.

 E:\msys64\mingw64.exe /bin/sh -c 'CHERE_INVOKING=1 $SHELL'

I removed -l because it was losing the current path.
I need $SHELL, as I'm using Zsh.

@fangly

This comment has been minimized.

Copy link

@fangly fangly commented Mar 30, 2017

With the exec bash solutions above, I always had the following error:

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

Based on the content of msys64/mingw64_shell.bat and these Mintty tips, I came up with a working solution. This is for a MinGW64 Bash shell only:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw]
@="Open MinGW here"
"Icon"="C:\\msys64\\msys2.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw\command]
@="C:\\msys64\\usr\\bin\\mintty -i /msys2.ico --dir \"%V/\" /bin/env MSYSTEM=MINGW64 CHERE_INVOKING=1 /usr/bin/bash -l"

[HKEY_CLASSES_ROOT\Directory\shell\mingw]
@="Open MinGW here"
"Icon"="C:\\msys64\\msys2.ico"

[HKEY_CLASSES_ROOT\Directory\shell\mingw\command]
@="C:\\msys64\\usr\\bin\\mintty -i /msys2.ico --dir \"%1/\" /bin/env MSYSTEM=MINGW64 CHERE_INVOKING=1 /usr/bin/bash -l"

Note that both right-clicking on the background or on the icon of a folder triggers the action.

@makefile

This comment has been minimized.

Copy link

@makefile makefile commented Dec 4, 2017

The above doesn't work for me,for I use Cygwin64,the following works fine.And I use exec bash to replace the parent shell.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_mingw64]
@="Cygwin Here"
"Icon"="\"D:\\cygwin64\\Cygwin-Terminal.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_mingw64\command]
@="d:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; exec bash'"

[HKEY_CLASSES_ROOT\Folder\shell\open_mingw64]
@="Cygwin Here"
"Icon"="\"D:\\cygwin64\\Cygwin-Terminal.ico\""

[HKEY_CLASSES_ROOT\Folder\shell\open_mingw64\command]
@="d:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; exec bash'"
@hiptkang

This comment has been minimized.

Copy link

@hiptkang hiptkang commented Dec 1, 2018

For some users...

registry file

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\msys2.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64\command]
@="C:\\msys64\\msys2_shell.cmd -mingw64 -where \"%V/\""

[HKEY_CLASSES_ROOT\Directory\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\msys2.ico\""

[HKEY_CLASSES_ROOT\Directory\shell\mingw64\command]
@="C:\\msys64\\msys2_shell.cmd -mingw64 -where \"%V/\""
@Mattiwatti

This comment has been minimized.

Copy link

@Mattiwatti Mattiwatti commented Feb 3, 2020

The command lines from @MacGyver27's .reg file worked fine for me so I didn't need to modify it. But here are some things to add that people may want to change to the above files:

  • If you add a key to HKEY_CLASSES_ROOT\Directory\shell, the menu item will be displayed when you right click on a folder in explorer. If you add a key to HKEY_CLASSES_ROOT\Directory\Background\shell, the menu item will be displayed when you right click on an empty area in a folder in explorer. If you add a key to HKEY_CLASSES_ROOT\Drive\shell, the menu item will be displayed when you right click on a drive. You may or may not want to add all three.
  • If your context menu is too cluttered you may want to enable the item for SHIFT+right clicks only. In this case you should add the following:
[HKEY_CLASSES_ROOT\xxx\shell\<msys2|mingw32|mingw64>]
"Extended"=""
"ShowBasedOnVelocityId"=dword:00639bc8
@ceremcem

This comment has been minimized.

Copy link

@ceremcem ceremcem commented Aug 6, 2020

For those who want make's autocompletion to work, replace the /command lines with this command, as applied in here.

@Hexlord

This comment has been minimized.

Copy link

@Hexlord Hexlord commented Sep 20, 2020

For some users...

registry file

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\msys2.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\mingw64\command]
@="C:\\msys64\\msys2_shell.cmd -mingw64 -where \"%V/\""

[HKEY_CLASSES_ROOT\Directory\shell\mingw64]
@="MinGW &64 Bash Here"
"Icon"="\"C:\\msys64\\msys2.ico\""

[HKEY_CLASSES_ROOT\Directory\shell\mingw64\command]
@="C:\\msys64\\msys2_shell.cmd -mingw64 -where \"%V/\""

The only option that worked for me with fresh MSYS2, thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.