Open Cygwin at a specific folder

后端 未结 29 2442
悲哀的现实
悲哀的现实 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:18

    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.

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

    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

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

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

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

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

    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.

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