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

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

每次我发射Cygwin。


当前回答

基于@LindseyD的答案,我创建了一个简单的BAT文件,在当前目录中打开cygwin,这可能是有用的(对我来说是)。假设在PATH中有cygwin的bin目录。

FOR /F %%x IN ('sh -c pwd') DO bash -l -i -c 'cd %%x; exec bash'

其他回答

在使用注册表的答案中,我发现在Windows 2008 R2 SP1上,您需要将Background从路径中删除。此外,由于chere和xhere不是cygwin64的一部分,这里有一个同时适用于两者的解决方案,它结合了注册表和Send To解决方案。将'E:\cygwin64'替换为您的安装位置:

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

创建一个bash文件move.sh,其中包含以下代码 C:\cygwin64\bin\run.exe -p /bin bash runFile.sh 这将启动Cygwin并执行Cygwin bin目录中的runFile.sh 假设你想要导航到一个特定的目录,比如E:\code 那么runFile.sh有如下代码cd E: cd代码

这是我用的。它不需要修改包或注册表。适用于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`'

要创建一个Windows快捷方式,在您自己选择的目录中启动Cygwin终端,请尝试以下操作:

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

可以在桌面上放置多个快捷方式,在各种经常访问的目录中打开Cygwin终端。

灵感来自解决方案张贴如何打开一个Cygwin shell在一个特定的目录从Netbeans?在superuser.com上。

在我的Windows电脑上,它没有显示:

切尔 -i -t 薄荷

因为薄荷shell是不可用的,但你可以选择各种其他shell,如ash bash cmd dash mksh pdksh posh tcsh zsh passwd。

所以我用:

Chere -i -s bash