249

How can I create a Cygwin shortcut that will open Cygwin at a specific folder? This would obviate having to type

cd /cygdrive/c/Users/Tom/Desktop/

each time I launch Cygwin.

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Randomblue
  • 112,777
  • 145
  • 353
  • 547
  • 2
    create a .bat file: here is a tutorial http://www.computerhope.com/batch.htm – goodolddays Sep 06 '12 at 09:48
  • Note: The chere package may need to be instantiated with administrator privileges. If you are caught by this, and are tempted to use `sudo`, you may not get the expected result. In this case, login as an admin user on the windows machine. – dreftymac Nov 21 '15 at 20:11

29 Answers29

446

When you install Cygwin (or if you’ve already installed it, download it again and start setup again to run an update), make sure that you select the chere package under the "Shells" category.

After Cygwin is launched, open up a Cygwin terminal (as an administrator) and type the command: chere -i -t mintty -s bash.

Now you should have "Bash Prompt Here" in the Windows right-click context menu.

(mintty is Cygwin's default terminal. If you don't choose it with the -t option, your "Bash Prompt Here" will use the same terminal as the Windows Command Prompt, which prevents horizontal resizing.)

Toolkit
  • 10,779
  • 8
  • 59
  • 68
two7s_clash
  • 5,755
  • 1
  • 27
  • 44
  • 40
    Awesome find, thanks! I discovered that you can specify the terminal you want to open using `-t`, e.g., to open mintty you use `chere -i -t mintty` – Kevin Condon Mar 06 '13 at 22:57
  • 2
    I don't see any chere package :/ UPDATE: not in the x64 version, but it is present in the 32bit one. – zupa Sep 10 '13 at 18:53
  • @zupa did you managed to install chere in your x64 version? Or do you have to install the 32 bit version? Cheers – pandita Sep 22 '13 at 01:07
  • @pandita not in the x64 version, and I didn't bother to reinstall. Went with paxdiablo's aliasing solution – zupa Sep 22 '13 at 05:49
  • 29
    Just tested with 64bit cygwin (1.7.27) and chere seems to now exist. pro-tip: remember to launch cygwin terminal with admin privileges. – BuildTheRobots Jan 15 '14 at 11:04
  • 11
    One more thing to note. If you already did this with `chere -i -t mintty -f` to force the overwrite. You will still need to run cygwin as an administrator as well. – Greg Jennings Feb 09 '14 at 17:29
  • 4
    here's a nice how-to on this with pictures: http://unitstep.net/blog/2009/05/16/open-cygwin-bash-shell-here/ – J-Dizzle Mar 30 '14 at 03:32
  • 29
    Had permission issues on W7x64 (Error (5): Access is denied. Hive not writable). Resolved by launching Cygwin as administrator. – DmitrySandalov Apr 16 '14 at 12:27
  • 2
    `chere`s for this answer :) Confirming working on x64. – Mike Miller Oct 01 '14 at 04:10
  • 3
    Excellent! `chere -i -t mintty -s zsh` got me the option: "open zsh prompt here". Just the ticket! – stib Oct 20 '14 at 03:33
  • 1
    This whole suggestion is a big waste of time based on the original question. It emulates linux....so use bashrc. @bschwagg has the answer below. – hubbardr Mar 20 '15 at 22:51
  • I don't understand... ok, so I have to run as *administrator" once for it to set things up, but then something is supposed to show up under a right click WHERE? I'm starting the app from the dock, which doesn't have all these right click options. – Michael May 10 '15 at 15:54
  • 17
    Cygwin had no default shell in my case, so adding `-s bash` to make `chere -i -t mintty -s bash` made this work for me – Bryce Guinta Jul 15 '15 at 17:12
  • Had to use the `-s bash` option too, thanks for the hint! – Czechnology Jul 15 '15 at 19:01
  • 5
    x64 has *bash* as default shell, but the the context text is the dumb `Bash Prompt Here`, so you may consider using `chere -i -t mintty -e "Open Cygwin Here"` instead. – not2qubit Sep 12 '15 at 14:35
  • 1
    Heads up if you run `tmux`: you have to exit it before trying `chere -i -t mintty`, otherwise you'll run into the admin privilege issues. – Shou Mar 30 '16 at 18:14
  • 1
    Tip: if you [install `apt-cyg`](http://stackoverflow.com/a/29291849/113632) when you first set up Cygwin, you don't have to re-run the setup wizard in order to install additional packages. I just ran `apt-cyg install chere` and I was up and running. – dimo414 Apr 22 '16 at 04:18
  • 2
    In latest versions you also need to specify shell via `-s bash` (or any other shell you need). – lukyer Jul 15 '16 at 12:20
  • Hm, my Cygwin installer doesn't have chere listed anywhere in the packages, only bash, dash, and mintty (and chere isn't recognize with all three of these installed.) I'm using setup-x86_64.exe from this week. – Aaron Jul 21 '16 at 15:59
  • 3
    If anybody wants to remove the context menu entry, simply swap the -i (install) argument for -u (uninstall), e.g: `chere -u -t mintty -s bash` – not an alien May 24 '19 at 15:32
  • Nowadays chere has a -c option to install it just for the current user, no admin privileges required. It still prints an access denied error because it cannot register the uninstaller with Windows. There is another flag -m to avoid that as well. Using -p you can see what it would do to the registry. – JayK Oct 16 '20 at 14:02
112

Here's what I use. It doesn't require chere package or registry tinkering. Works on Windows 7.

Go to your "Send To" folder:

C:\Users\<your_user_name>\AppData\Roaming\Microsoft\Windows\SendTo

Create a shortcut named Bash Here having this in the Target field:

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico  C:\cygwin\bin\bash.exe  -l -c "cd \"$0\" ; exec bash"

In the Windows Explorer, you right-click on a folder & select Send To > Bash Here.

And here's the opposite trick, opening a Windows Explorer in your current bash dir. Create this alias:

alias winx='/cygdrive/c/Windows/explorer.exe /e,\`cygpath -w .\`'

Note: the cygpath -w . part above is enclosed in back-ticks.

Now just type winx at the bash prompt, and a Win Explorer pops up there.

Note: If winx directs you to your documents folder, try

alias winx='/cygdrive/c/Windows/explorer.exe /e,`cygpath -w $PWD`'
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
LindseyD
  • 1,129
  • 1
  • 7
  • 2
  • 3
    Very nice trick, but the `winx` alias didn't work on my Cygwin setup. I had to remove both backslashes and replace `.` with `$PWD` for it to work. – not2qubit Feb 26 '14 at 14:53
  • What if the shortcut (adapted to use the Cygwin64 path of my install) opens cygwin to my user folder? :( Maybe this only works with 32-bit Cygwin? – Alex Hall Nov 18 '15 at 17:27
  • 1
    This one is also working for me `alias winx='/cygdrive/c/Windows/explorer.exe /e,$(cygpath -wa .)'` – Wakan Tanka May 03 '16 at 19:42
  • 3
    In cygwin 2.6.0 (on Win 7 x64) it can be done much easier: `cygstart .` to open Explorer with the current folder, or any folder syntax `cygstart ..`, `cygstart /your/path` etc... – 244an Oct 22 '16 at 09:39
  • 2
    Warning: `C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico C:\cygwin\bin\bash.exe -l -c "cd \"$0\" ; exec bash` keeps file handle open to `$0` directory, even after you change working directory to something else. What's worse spawning copy of the window (`ALT+F2`), even when you already have changed working directory, opens another file handle to `$0`. This may interfere with some operations that may want to delete/modify `$0` in any process. If you get 'Permission Denied' error when accessing `$0` this might be the cause – matt Aug 18 '17 at 10:47
34

I made a .reg file that puts an "Open Cygwin Here" option in the right-click context menu. It depends on the Cygwin "chere" package, which you can install using apt-cyg if you didn't install it in the initial setup.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
@="Open Cygwin Here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
@="C:\\cygwin\\bin\\mintty.exe -e /bin/xhere /bin/bash.exe"
John Thompson
  • 1,674
  • 1
  • 20
  • 35
  • 7
    For those who are wondering how to use this, just copy the gray-background text and put it in a text file called "foo.reg" and double click it. – Andrew Moylan Aug 28 '13 at 18:30
  • 3
    +1 the best solution here. And thanks for mentioning `apt-cyg`, I didn't know about this tool – user11153 Jul 23 '14 at 08:21
  • This was exactly what I was looking for, and it even helped me with other things because even the Microsoft site didn't get me the same result. – FilBot3 Oct 02 '14 at 16:55
  • I had to change to "cygwin" but I get this error: "Failed to run /bin/xhere: No such file or directory" – Totty.js Oct 28 '15 at 20:42
  • 1
    @Totty.js are you sure you've installed the 'chere' package in Cygwin? – Jeutnarg Jun 20 '16 at 17:04
34

From the cygwin terminal, run this command:

echo "cd your_path" >> ~/.bashrc

The .bashrc script is run when you open a new bash session. The code above with change to the your_path directory when you open a new cygwin session.

bschwagg
  • 779
  • 7
  • 9
20

For cygwin64 or installations without chere you can use the following command in a registry entry (assuming windows due to your path, also assuming cygwin installation directory is c:\cygwin64)

C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd "`cygpath "%V"`"; bash'

Works on Windows 7 and 8 Registry file available for download here: http://tomkay.me/blog/Cygwin64---Open-Here-18

Windows Registry Editor Version 5.00
; Open cygwin to folder
; http://tomkay.me - Tom Kay

[HKEY_CLASSES_ROOT\Folder\shell\open_cygwin]
@="Open Cygwin Here"

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

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_cygwin]
@="Open Cygwin Here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\open_cygwin\command]
@="C:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; bash'"
Tom Kay
  • 1,512
  • 15
  • 25
  • Can you explain why you have 3 (x2) registry entries? – not2qubit Feb 26 '14 at 19:53
  • 1
    they are for Directory, Drive and Background contexts – Tom Kay Mar 05 '14 at 20:48
  • Finally, one solution which worked for me, although I have some issues understanding it completely ;-) [the 'bash' after 'exec bash']. Hint: you can replace the 3 entries with 1: 'Folder' instead of 'Directory', 'Drive' and 'Background'. – t0r0X Mar 28 '14 at 16:41
  • with just 'Folder', the link appears in the context menu of a drive, but fails to execute. However, I have been able to cut down to 2 entries with 'Folder' and 'Directory\Background' – Tom Kay Apr 22 '14 at 14:40
  • 1
    For emacs: "C:\\cygwin\\bin\\mintty.exe -i /Cygwin-Terminal.ico /bin/bash -l -c 'emacs \"`cygpath \"%V\"`\";'" – Jan Matousek Sep 01 '14 at 19:16
  • Thanks for stating the simple `mintty` incantation with the right amount of escaping. This made it easier to adapt your solution to my FreeCommander setup. – ojdo Feb 19 '17 at 19:59
  • This ``/bin/sh -lc 'cd \"`cygpath \"%V\"`\"; bash'`` will cause `mintty` to always ask **`Processes are running in session ... Close anyway?`** when closing the `mintty` terminal by hitting the window X close button. – Evandro Coan Nov 15 '19 at 20:13
  • @user The last command replaces `bash` with `exec bash` to avoid a confirmation prompt when closing. – lovestackh343 Oct 20 '20 at 03:25
11

If you want to have that directory as your default, simply add a cd statement to your ~/.profile file.

What I tend to do is use that method to set my usual directory, plus define aliases for my common cases as well:

alias tom="cd /users/tom"

or your equivalent. This lets me change directories very fast.

me_and
  • 15,158
  • 7
  • 59
  • 96
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Does that alias have to be added to the `~/.profile` file, too, or just run once? – iono Mar 18 '13 at 07:18
  • 2
    @tomeoftom, if you just run that within a shell, it will only affect that shell. It won't affect any others you start. So, if you want it to be always available, you need to put it in one of your startup files (of which `~/.profile` is one possibility). – paxdiablo Mar 18 '13 at 08:58
  • 1
    it didn't work for me when put in ~/.profile, but ~/.bashrc worked. – zupa Sep 10 '13 at 18:29
  • 1
    @zupa, the rules as to which startup files are sourced are reasonably complicated (though it's all there in the `bash` man page if you dig deep enough). That's why I stated `.profile` as one possibility. – paxdiablo Sep 11 '13 at 00:53
  • 1
    .profile ultimately sources .bashrc so you might want to append that command into bashrc instead. (.profile didn't work for me) – laertis Sep 29 '16 at 11:05
  • Just one nitpick, @laertis: whether or not `.profile` sources `.bashrc` depends *entirely* on the contents of `.profile`. It may or it may not, depending on how you've set things up. – paxdiablo Sep 29 '16 at 14:01
10

As two7s_clash said you first need to install chere package and setup mintty:

  1. Open Cygwin terminal as administrator
  2. apt-cyg install chere
  3. chere -i -t mintty

You are now able to open cygwin in specific directory with a Right mouse click in Windows Explorer (Context Menu) and select "Bash Prompt Here".

You can also open cygwin from a specific directory using windows command prompt:

  1. Open windows command prompt
  2. Navigate (cd) to custom directory
  3. Execute C:\cygwin64\bin\mintty.exe C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l

    This command will open cygwin with current directory taken from command prompt.

FreeCommander

This command can also be used to open cygwin from custom file manager, like FreeCommander.

To open cygwin with current directory taken from FreeCommander, do the following:

  1. Tools -> Favorite Tools -> Favorite tools edit... (Ctrl + Shift + Y)
  2. Add a new toolbar (+ Icon), Shortcut: Insert

    • Name: cygwin
    • Program or folder: C:\cygwin64\bin\mintty.exe
    • Start folder: %ActivDir%
    • Parameter: C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l

You can add custom shortcut to open cygwin from FreeCommander:

  1. Tools -> Define keyboard shortcuts
  2. Scroll down to "Favorite tool 01" (or "Favorite tool N")
  3. Assign new shortcut key: I use Ctrl + Shift + T

Great reference: MinTTY Wiki, article Tips: Starting in a particular directory

ojdo
  • 8,280
  • 5
  • 37
  • 60
nexayq
  • 606
  • 1
  • 9
  • 13
8

I use and Icon to launch my cygwin without the chere package.

  1. Create a shortcut on my desktop for the cygwin terminal.
  2. R-click the icon and select properties.
  3. On the shortcut tab, use this for the TARGET: C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -c 'cd'
  4. For START IN, Put the path of the dir/folder where you want to launch cygwin. i.e. C:\some\dir\name\here
Doug
  • 2,783
  • 6
  • 33
  • 37
  • ok 2 things 1. appending `-c` in "Target" makes no difference as long you provide a path in "Start In" 2. this solution creates an issue with `PATH`. cygwin fails to prepend `/usr/local/bin:/usr/bin` in the system PATH leaving unable to invoke some of its binaries The configuration probably reside in `/etc/profile` >> ` if [ ${CYGWIN_NOWINPATH-addwinpath} = "addwinpath" ] ; then ` – laertis Oct 13 '16 at 11:17
6

To create a Windows shortcut that launches a Cygwin terminal in a directory of your own choosing, try the following:

  • Right-click on the Windows desktop, select 'New', and then select 'Shortcut'.

  • For location of the item, enter the following text, changing the mintty path as needed and substituting the name of the desired directory where indicated.

    C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd DESIRED-DIRECTORY; exec bash'
    

    For example, the OP would use the following text:

    C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd /cygdrive/c/Users/Tom/Desktop/; exec bash'
    
  • Click 'Next'.

  • Enter the desired name for the shortcut and click 'Finish'.

Multiple shortcuts can be placed on the desktop to open Cygwin terminals in various often-accessed directories.

Inspired by solution posted on How to open a Cygwin shell at a specific directory from Netbeans? at superuser.com.

Patrick Kelly
  • 1,301
  • 1
  • 16
  • 25
3

I have made a registry edit script to open Cygwin at any folder you right click. It's on my GitHub.

Here's my GitHub

Sample RegEdit code from Github for 64-bit machines:

REGEDIT4

[HKEY_CLASSES_ROOT\Directory\shell\CygwinHere]
@="&Cygwin Bash Here"

[HKEY_CLASSES_ROOT\Directory\shell\CygwinHere\command]
@="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\CygwinHere]
@="&Cygwin Bash Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\CygwinHere\command]
@="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""
M--
  • 25,431
  • 8
  • 61
  • 93
umer936
  • 49
  • 3
3

I used the following lines of code to start zsh in the current directory in Win7.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
@="Open Cygwin Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
@="\"C:\\Programmieren\\cygwin64\\bin\\mintty.exe\" -i /Cygwin-Terminal.ico /bin/zsh --login -c 'cd \"%V\";zsh'"

note that i used %V instead of %L or %1 (since both didn't work for me)

H. Hess
  • 213
  • 1
  • 5
3

Find file Cygwin.bat and make content like this:

@echo off
set newpath=%cd:\=/%
pushd "%~dp0"
chdir bin
bash --login -i -c "cd \"%newpath%\"; exec bash"

Add path to cygwin.bat to environment PATH.

Now in any folder you can type to address bar:

cygwin

Also you can type it when you in cmd.exe

Geograph
  • 2,274
  • 23
  • 23
3

When a fresh install is needed, I create a Windows "user environment variable " named HOME and assigns it the path of wherever "My Documents" reside.

The cygwin installer detects the HOME variable, automatically translates this into a cygpath and selects this it to be my ~ directory.

This has worked fine for every workstation I have used professionally the last 5 years (about 3 or 4, Win7). I have always been the only user on these machines, cannot say what the effect is.

Adam.at.Epsilon
  • 263
  • 2
  • 12
3

Save the following code as a file: cygwin_bash.reg

This will add opening Cygwin in the current directory and opening Cygwin in the specified folder at the same time.

Use ".bashrc" instead of ".bash_profile" configuration. Because of exec bash. .bashrc is executed for interactive non-login shells. see: https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\z_cygwin_bash]
@="Cygwin Here"
"Icon"="C:\\cygwin64\\Cygwin.ico"

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

[HKEY_CLASSES_ROOT\Directory\shell\z_cygwin_bash]
@="Cygwin Here"
"Icon"="C:\\cygwin64\\Cygwin.ico"

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

lovestackh343
  • 581
  • 5
  • 6
2

Open Cygwin terminal as Administrator

In powershell (using chocolatey):

choco install cyg-get

In cygwin Will Install right-click menu

cyg-get install chere
chere -i

Now you can right click and use "Bash Prompt Here" in any folder.

Jonathan
  • 6,741
  • 7
  • 52
  • 69
1

In the answer that uses the registry, I found that on Windows 2008 R2 SP1, you need to drop the Background out of the path. Further, since the chere and xhere are not part of cygwin64, here is a solution that works for both, combining the registry and the Send To solutions. Replace 'E:\cygwin64' with your install location:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash]
@="Open Cygwin Here"

[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash\command]
@="E:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico --exec /bin/bash.exe --login -c \"cd '%1' ; exec bash -rcfile ~/.bashrc\""
M--
  • 25,431
  • 8
  • 61
  • 93
mpersico
  • 766
  • 7
  • 19
1

You can add the icon to the shell by adding an Icon field set to the path to your Cygwin.ico file.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
@="Cygwin"
"Icon"="\"C:\\cygwin64\\Cygwin.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
@="C:\\cygwin64\\bin\\mintty.exe -e /bin/xhere /bin/bash.exe"
Palec
  • 12,743
  • 8
  • 69
  • 138
Mike DeRoy
  • 133
  • 7
  • I think a prerequisite to xhere's existence is the installation of chere, as mentioned in other answers. – Samuel Mar 11 '20 at 19:07
1

On my Windows machine it was not taking:

chere -i -t mintty

Because mintty shell was not available,but you might have choice of various other shells like ash bash cmd dash mksh pdksh posh tcsh zsh passwd.

so I used :

chere -i -s bash

user3065757
  • 475
  • 1
  • 5
  • 14
  • Mintty is not a shell, it is a terminal emulator. – Palec Apr 05 '17 at 09:47
  • How does this answer the original question? – Leigh Apr 06 '17 at 19:52
  • This will provide the help to those who do not have mintty in their system and get error when trying to attempt the solution provided above, I also followed the solution provided above but it didnt work on my windows machine, but my answer solved the problem. – user3065757 Apr 07 '17 at 14:34
0

This is the only Cygwin64 registry solution that worked for me in Windows 8.1:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\mintty]
@="Mintty from Here"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\mintty\command]
@="C:\\cygwin64\\bin\\mintty.exe -h always -e /usr/bin/ash -c 'cd  \"$(/usr/bin/cygpath \"%L\")\";  exec /usr/bin/bash  '"

Make sure you modify your 'C:\cygwin64' path as necessary.

Smyrnian
  • 701
  • 9
  • 15
0

I have created the batch file and put it to the Cygwin's /bin directory. This script was developed so it allows to install/uninstall the registry entries for opening selected folders and drives in Cygwin. For details see the link http://with-love-from-siberia.blogspot.com/2013/12/cygwin-here.html.

update: This solution does the same as early suggestions but all manipulations with Windows Registry are hidden within the script.

Perform the command to install

cyghere.bat /install

Perform the command to uninstall

cyghere.bat /uninstall
jsxt
  • 1,097
  • 11
  • 28
0

I had also problem with git, that used to "steal" my cygwin commands - so i needed to run
C:\cygwin\bin\mintty.exe -
but after installing chere and executing chere -i -t mintty -f as admin (see above), you can simply use :
C:\cygwin\bin\mintty.exe -e /bin/xhere /bin/bash.exe "."
I added this in Total Commander as custom button (right click on panel > add ...) and it works very well.

Jakub Michalko
  • 2,099
  • 1
  • 11
  • 12
0

Create a bash file say move.sh which has the following code C:\cygwin64\bin\run.exe -p /bin bash runFile.sh This starts the Cygwin and executes the runFile.sh present in the bin directory of Cygwin Suppose you want to navigate to a specific directory say E:\code then runFile.sh has the following code cd E: cd code

0

You can just open cygwin terminal and write: cd and after drag n drop the folder you want end enter!

Panagiotis
  • 163
  • 2
  • 9
  • While this doesn't fully solve the question asked, it is a very useful tip. Thanks. – RoG Dec 14 '18 at 08:32
0

Finally an answer which is independent of Cygwin itself.

This uses the fact that, if I am on the directory C:\\Cool and I call the command C:\\Cygwin\\bin\\mintty.exe, mintty will automatically open on the current directory, i.e., C:\\Cool.

First, you will need to create the file C:\\Cygwin\\silent_run.vbs with the following contents:

Function EnquoteString(argument)
  EnquoteString = Chr(34) & argument & Chr(34)
End Function

arglist = ""
With WScript.Arguments
    For Each arg In .Unnamed
        ' Wscript.Echo "Unnamed: " & arg
        If InStr(arg, " ") > 0 Then
            ' arg contains a space
            arglist = arglist & " " & EnquoteString(arg)
        Else
            arglist = arglist & " " & arg
        End If
    Next
End With

CreateObject("Wscript.Shell").Run Trim( arglist ), 0, False

Next, to install this answer, you will use a Windows Registry file. For that, just put the contents of the following file into a file named C:\\Cygwin\\AddMinttyToContextMenu.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
@="Terminal Here"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here\Command]
@="\"C:\\Cygwin\\bin\\mintty.exe\" -w max"


[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
@="Terminal Here"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here\Command]
@="cmd.exe /c cd /d \"%V\" && wscript \"C:\\Cygwin\\silent_run.vbs\" \"C:\\Cygwin\\bin\\mintty.exe\" -w max"

Now, Fix all hard coded paths, i.e, C:\\Cygwin to the actual location where your Cygwin installation is on.

Then, just open the file C:\\Cygwin\\AddMinttyToContextMenu.reg to install your new registry entries and you are done.

The file C:\\Cygwin\\AddMinttyToContextMenu.reg works by opening first a cmd.exe, changing to the directory where you are in, then, calling C:\\Cygwin\\silent_run.vbs to open the C:\\Cygwin\\bin\\mintty.exe terminal with the command line options -w max, i.e., to open it maximized.

The script C:\\Cygwin\\silent_run.vbs is required to open the C:\\Cygwin\\bin\\mintty.exe terminal without keeping the first cmd.exe we opened, open.

The first entry of C:\\Cygwin\\AddMinttyToContextMenu.reg does not use C:\\Cygwin\\silent_run.vbs because by default the HKEY_CLASSES_ROOT\Directory\Background\shell keys are already open in the current directory, then, we can just call C:\\Cygwin\\bin\\mintty.exe directly to get it working out of the box.

References:

  1. How add context menu item to Windows Explorer for folders
  2. VBScript pass commandline argument in paths with spaces
  3. How to pass a command with spaces and quotes as a single parameter to CScript?
  4. calling vbscript from another vbscript file passing arguments
  5. https://ss64.com/vb/syntax-args.html
  6. Check if string contains space
  7. Running command line silently with VbScript and getting output?
  8. http://www.vbsedit.com/html/6f28899c-d653-4555-8a59-49640b0e32ea.asp
  9. https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way
  10. How to run Batch script received as argument on VBscript?
  11. Can I pass an argument to a VBScript (vbs file launched with cscript)?
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
-1
@echo off
C:
SET mypath=%~dp0
c:\cygwin\bin\bash -c "cd '%mypath%'; export CHERE_INVOKING=1; exec /bin/bash --login -i"

Copy above commands in a text file and save it as .bat in any of "your folder of interest". It should open cygwin in "your folder of interest".

Kalyan
  • 1
  • 1
-1

based on @LindseyD answer I created a simple BAT file, that opens cygwin in current directory, it may be useful (for me it is). Assuming that You have cygwin's bin directory in PATH.

FOR /F %%x IN ('sh -c pwd') DO bash -l -i -c 'cd %%x; exec bash'
Roman Hocke
  • 4,137
  • 1
  • 20
  • 34
-1

I don't know why I had to wast so much time, but this works for me on win 10, 64 bit:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
@="Open Cygwin Here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
@="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""
Totty.js
  • 15,563
  • 31
  • 103
  • 175
-1

Probably the simplest one:

1) Create file foo.reg

2) Insert content:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\background\shell\open_mintty]
@="open mintty"

[HKEY_CLASSES_ROOT\Directory\background\shell\open_mintty\command]
@="cmd /C mintty"

3) Execute foo.reg

Now just right-click in any folder, click open mintty and it will spawn mintty in that folder.

kungfooman
  • 4,473
  • 1
  • 44
  • 33
-2

Best to do like below:

HKEY_CLASSES_ROOT\Directory\shell\BashHere
Enter Data: Bash Here

HKEY_CLASSES_ROOT\Directory\shell\BashHere\command
Enter Data: 

cmd.exe /c C:\cygwin\bin\bash.exe --login -c "cd '%1'; exec /bin/bash"
Shashi Ranjan
  • 353
  • 2
  • 8