如何创建在特定文件夹中打开Cygwin的Cygwin快捷方式?这样就不用打字了

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

每次我发射Cygwin。


当前回答

我已经做了一个注册表编辑脚本打开Cygwin在任何文件夹你右键单击。在我的GitHub上。

这是我的GitHub

来自Github的64位机器RegEdit示例代码:

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\""

其他回答

以管理员身份打开Cygwin终端

在powershell中(使用巧克力):

choco install cyg-get

在cygwin 将安装右键菜单

cyg-get install chere
chere -i

现在您可以在任何文件夹中单击右键并使用“Bash Prompt Here”。

这是我用的。它不需要修改包或注册表。适用于Windows 7。

进入“发送到”文件夹:

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

在目标字段中创建一个名为Bash Here的快捷方式:

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

在Windows资源管理器中,右键单击一个文件夹并选择发送到> Bash Here。

这里有一个相反的技巧,在当前bash目录下打开Windows资源管理器。创建这个别名:

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

注:cygpath为-w。以上部分用反引号括起来。

现在只要在bash提示符下输入winx,就会弹出一个Win资源管理器。

注意:如果winx引导您到文档文件夹,请尝试

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

对于cygwin64或没有chere的安装,您可以在注册表项中使用以下命令(假设windows由于您的路径,也假设cygwin安装目录为c:\cygwin64)

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

适用于Windows 7和8 注册表文件可在这里下载: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'"

将以下代码保存为文件:cygwin_bash.reg

这将同时添加在当前目录中打开Cygwin和在指定文件夹中打开Cygwin。

使用”。Bashrc“而不是”。bash_profile”配置。由于exec bash. .bashrc是为交互式非登录shell执行的。参见: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'"

@echo off
C:
SET mypath=%~dp0
c:\cygwin\bin\bash -c "cd '%mypath%'; export CHERE_INVOKING=1; exec /bin/bash --login -i"

将上述命令复制到一个文本文件中,并将其保存为。bat在“您感兴趣的文件夹”中。 它应该在“您感兴趣的文件夹”中打开cygwin。