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

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

每次我发射Cygwin。


当前回答

将以下代码保存为文件: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'"

其他回答

最后一个答案是独立于Cygwin本身。

这使用的事实是,如果我在目录C:\\Cool,我调用命令C:\\Cygwin\\bin\\mintty.exe, mintty将自动打开当前目录,即C:\\Cool。

首先,您需要创建文件C:\\Cygwin\\silent_run。VBS,内容如下:

Function EnquoteString(argument)
  EnquoteString = Chr(34) & argument & Chr(34)
End Function

arglist = ""
With WScript.Arguments
    For Each arg In .Unnamed
        ' Wscript.Echo "Unnamed: " & arg
        If InStr(arg, " ") > 0 Then
            ' arg contains a space
            arglist = arglist & " " & EnquoteString(arg)
        Else
            arglist = arglist & " " & arg
        End If
    Next
End With

CreateObject("Wscript.Shell").Run Trim( arglist ), 0, False

接下来,要安装这个答案,您将使用一个Windows注册表文件。为此,只需将以下文件的内容放入名为C:\\Cygwin\\AddMinttyToContextMenu.reg的文件中

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
@="Terminal Here"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here\Command]
@="\"C:\\Cygwin\\bin\\mintty.exe\" -w max"


[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
@="Terminal Here"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here\Command]
@="cmd.exe /c cd /d \"%V\" && wscript \"C:\\Cygwin\\silent_run.vbs\" \"C:\\Cygwin\\bin\\mintty.exe\" -w max"

现在,修复所有硬编码路径,即C:\\Cygwin到您的Cygwin安装的实际位置。

然后,只需打开文件C:\\Cygwin\\AddMinttyToContextMenu。Reg来安装新的注册表项,这样就完成了。

文件C:\\Cygwin\\AddMinttyToContextMenu。reg的工作原理是首先打开cmd.exe,切换到您所在的目录,然后调用C:\\Cygwin\\silent_run。vbs打开C:\\Cygwin\\bin\\mint .exe终端,用命令行选项-w max,即最大限度地打开它。

脚本C:\\Cygwin\\silent_run。需要vbs来打开C:\\Cygwin\\bin\\mint .exe终端而不保留我们打开的第一个cmd.exe,打开。

C:\\Cygwin\\AddMinttyToContextMenu的第一个条目。reg不使用C:\\Cygwin\\silent_run。因为默认情况下HKEY_CLASSES_ROOT\Directory\Background\shell键已经在当前目录中打开,那么,我们可以直接调用C:\\Cygwin\\bin\\mint .exe来让它开箱工作。

引用:

How add context menu item to Windows Explorer for folders VBScript pass commandline argument in paths with spaces How to pass a command with spaces and quotes as a single parameter to CScript? calling vbscript from another vbscript file passing arguments https://ss64.com/vb/syntax-args.html Check if string contains space Running command line silently with VbScript and getting output? http://www.vbsedit.com/html/6f28899c-d653-4555-8a59-49640b0e32ea.asp https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way How to run Batch script received as argument on VBscript? Can I pass an argument to a VBScript (vbs file launched with cscript)?

我使用和图标启动我的cygwin没有chere包。

在我的桌面上为cygwin终端创建一个快捷方式。 右击图标并选择属性。 在快捷选项卡上,对TARGET使用这个: C:\cygwin64\bin\mint .exe -i /Cygwin-Terminal.ico -c 'cd' 对于START IN,将目录/文件夹的路径放在您想要的位置 启动cygwin。例如C: \一些\ dir \名字\

这是唯一的Cygwin64注册表解决方案,为我工作在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  '"

请确保根据需要修改'C:\cygwin64'路径。

您可以通过在Cygwin.ico文件的路径中添加icon字段来将图标添加到shell中。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
@="Cygwin"
"Icon"="\"C:\\cygwin64\\Cygwin.ico\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
@="C:\\cygwin64\\bin\\mintty.exe -e /bin/xhere /bin/bash.exe"

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