如何创建在特定文件夹中打开Cygwin的Cygwin快捷方式?这样就不用打字了
cd /cygdrive/c/Users/Tom/Desktop/
每次我发射Cygwin。
如何创建在特定文件夹中打开Cygwin的Cygwin快捷方式?这样就不用打字了
cd /cygdrive/c/Users/Tom/Desktop/
每次我发射Cygwin。
当前回答
我已经创建了批处理文件,并将其放到Cygwin的/bin目录中。开发此脚本的目的是允许安装/卸载注册表项,以便在Cygwin中打开选定的文件夹和驱动器。详情请参见http://with-love-from-siberia.blogspot.com/2013/12/cygwin-here.html。
更新:此解决方案与早期建议相同,但Windows注册表的所有操作都隐藏在脚本中。
执行安装命令
cyghere.bat /install
执行卸载命令
cyghere.bat /uninstall
其他回答
这是我用的。它不需要修改包或注册表。适用于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上。
我使用以下几行代码在Win7的当前目录中启动zsh。
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'"
请注意,我使用%V而不是%L或%1(因为两者都不适合我)
最好这样做:
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"
在cygwin终端运行如下命令:
回显"cd your_path" >> ~/.bashrc
在打开一个新的bash会话时运行.bashrc脚本。当您打开一个新的cygwin会话时,上面的代码改变了your_path目录。