Open Cygwin at a specific folder

后端 未结 29 2440
悲哀的现实
悲哀的现实 2020-12-12 08:49

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/

相关标签:
29条回答
  • 2020-12-12 09:14

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

    0 讨论(0)
  • 2020-12-12 09:14
    @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".

    0 讨论(0)
  • 2020-12-12 09:14

    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\""
    
    0 讨论(0)
  • 2020-12-12 09:15

    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.

    0 讨论(0)
  • 2020-12-12 09:16

    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'"
    
    0 讨论(0)
  • 2020-12-12 09:17

    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.

    0 讨论(0)
提交回复
热议问题