windows 在特定文件夹中打开 Cygwin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9637601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:20:38  来源:igfitidea点击:

Open Cygwin at a specific folder

windowscygwin

提问by Randomblue

How can I create a Cygwin shortcut that will open Cygwin at a specific folder? This would obviate having to type

如何创建将在特定文件夹中打开 Cygwin 的 Cygwin 快捷方式?这将避免必须键入

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

each time I launch Cygwin.

每次我启动 Cygwin 时。

回答by two7s_clash

When you install Cygwin (or if you've already installed it, download it again and start setup again to run an update), make sure that you select the cherepackage under the "Shells" category.

当您安装 Cygwin 时(或者如果您已经安装了它,请再次下载它并再次开始安装以运行更新),请确保您选择chere了“Shell”类别下的包。

After Cygwin is launched, open up a Cygwin terminal (as an administrator) and type the command: chere -i -t mintty -s bash.

Cygwin 启动后,打开 Cygwin 终端(以管理员身份)并输入命令:chere -i -t mintty -s bash.

Now you should have "Bash Prompt Here" in the Windows right-click context menu.

现在您应该在 Windows 右键单击​​上下文菜单中有“Bash Prompt Here”。

(minttyis Cygwin's default terminal. If you don't choose it with the -toption, your "Bash Prompt Here" will use the same terminal as the Windows Command Prompt, which prevents horizontal resizing.)

mintty是 Cygwin 的默认终端。如果你没有选择它-t,你的“Bash Prompt Here”将使用与 Windows 命令提示符相同的终端,这会阻止水平调整大小。)

回答by LindseyD

Here's what I use. It doesn't require cherepackage or registry tinkering. Works on Windows 7.

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

Go to your "Send To" folder:

转到您的“发送到”文件夹:

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

Create a shortcut named Bash Herehaving this in the Targetfield:

Bash HereTarget字段中创建一个名为的快捷方式:

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico  C:\cygwin\bin\bash.exe  -l -c "cd \"
alias winx='/cygdrive/c/Windows/explorer.exe /e,\`cygpath -w .\`'
\" ; exec bash"

In the Windows Explorer, you right-click on a folder & select Send To > Bash Here.

在 Windows 资源管理器中,右键单击文件夹并选择Send To > Bash Here

And here's the opposite trick, opening a Windows Explorer in your current bash dir. Create this alias:

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

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

Note: the cygpath -w .part above is enclosed in back-ticks.

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

Now just type winxat the bash prompt, and a Win Explorer pops up there.

现在只需winx在 bash 提示符下键入,就会弹出一个 Win Explorer。

Note: If winx directs you to your documents folder, try

注意:如果 winx 将您定向到您的文档文件夹,请尝试

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"

回答by bschwagg

From the cygwin terminal, run this command:

从 cygwin 终端,运行以下命令:

echo "cd your_path" >> ~/.bashrc

echo "cd your_path" >> ~/.bashrc

The .bashrc script is run when you open a new bash session. The code above with change to the your_pathdirectory when you open a new cygwin session.

.bashrc 脚本在您打开新的 bash 会话时运行。当您打开一个新的 cygwin 会话时,上面的代码会更改为your_path目录。

回答by John Peter Thompson Garcés

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-cygif you didn't install it in the initial setup.

我制作了一个 .reg 文件,在右键单击上下文菜单中放置了一个“在此处打开 Cygwin”选项。这取决于 Cygwin“chere”包,如果您没有在初始设置中安装它,您可以使用apt-cyg安装它。

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

回答by Tom Kay

For cygwin64 or installations without chere you can use the following command in a registry entry (assuming windows due to your path, also assuming cygwin installation directory is c:\cygwin64)

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

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

Works on Windows 7 and 8 Registry file available for download here: http://tomkay.me/blog/Cygwin64---Open-Here-18

适用于 Windows 7 和 8 注册表文件可在此处下载:http: //tomkay.me/blog/Cygwin64---Open-Here-18

alias tom="cd /users/tom"

回答by paxdiablo

If you want to have that directory as your default, simply add a cdstatement to your ~/.profilefile.

如果您想将该目录作为默认目录,只需cd~/.profile文件中添加一条语句即可。

What I tend to do is use that method to set my usual directory, plus define aliases for my common cases as well:

我倾向于使用该方法来设置我常用的目录,并为我的常见情况定义别名:

C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd DESIRED-DIRECTORY; exec bash'

or your equivalent. This lets me change directories very fast.

或您的等价物。这让我可以非常快速地更改目录。

回答by nexayq

As two7s_clash said you first need to install cherepackage and setup mintty:

正如two7s_clash所说,您首先需要安装chere软件包并设置mintty:

  1. Open Cygwin terminal as administrator
  2. apt-cyg install chere
  3. chere -i -t mintty
  1. 以管理员身份打开 Cygwin 终端
  2. apt-cyg install chere
  3. chere -i -t mintty

You are now able to open cygwin in specific directory with a Right mouse click in Windows Explorer (Context Menu) and select "Bash Prompt Here".

您现在可以在 Windows 资源管理器(上下文菜单)中右键单击特定目录中的 cygwin,然后选择“Bash Prompt Here”。

You can also open cygwin from a specific directory using windows command prompt:

您还可以使用 Windows 命令提示符从特定目录打开 cygwin:

  1. Open windows command prompt
  2. Navigate (cd) to custom directory
  3. Execute C:\cygwin64\bin\mintty.exe C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l

    This command will open cygwin with current directory taken from command prompt.

  1. 打开windows命令提示符
  2. 导航 ( cd) 到自定义目录
  3. 执行 C:\cygwin64\bin\mintty.exe C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l

    此命令将使用从命令提示符获取的当前目​​录打开 cygwin。

FreeCommander

自由指挥官

This command can also be used to open cygwin from custom file manager, like FreeCommander.

此命令还可用于从自定义文件管理器(如 FreeCommander)打开 cygwin。

To open cygwin with current directory taken from FreeCommander, do the following:

要使用从 FreeCommander 获取的当前目​​录打开 cygwin,请执行以下操作:

  1. Tools -> Favorite Tools -> Favorite tools edit... (Ctrl + Shift + Y)
  2. Add a new toolbar (+ Icon), Shortcut: Insert

    • Name: cygwin
    • Program or folder: C:\cygwin64\bin\mintty.exe
    • Start folder: %ActivDir%
    • Parameter: C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l
  1. 工具 -> 收藏工具 -> 收藏工具编辑... (Ctrl + Shift + Y)
  2. 添加一个新的工具栏(+图标),快捷方式:插入

    • 名称: cygwin
    • 程序或文件夹: C:\cygwin64\bin\mintty.exe
    • 开始文件夹: %ActivDir%
    • 范围: C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l

You can add custom shortcut to open cygwin from FreeCommander:

您可以添加自定义快捷方式以从 FreeCommander 打开 cygwin:

  1. Tools -> Define keyboard shortcuts
  2. Scroll down to "Favorite tool 01" (or "Favorite tool N")
  3. Assign new shortcut key: I use Ctrl+ Shift+ T
  1. 工具 -> 定义键盘快捷键
  2. 向下滚动到“最喜欢的工具 01”(或“最喜欢的工具 N”)
  3. 指定新的快捷键:我用Ctrl+ Shift+T

Great reference: MinTTY Wiki, article Tips: Starting in a particular directory

很好的参考:MinTTY Wiki,文章提示:从特定目录开始

回答by Doug

I use and Icon to launch my cygwin without the cherepackage.

我使用和 Icon 在没有chere包的情况下启动我的 cygwin 。

  1. Create a shortcut on my desktop for the cygwin terminal.
  2. R-click the icon and select properties.
  3. On the shortcut tab, use this for the TARGET: C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -c 'cd'
  4. For START IN, Put the path of the dir/folder where you want to launch cygwin. i.e. C:\some\dir\name\here
  1. 在我的桌面上为 cygwin 终端创建一个快捷方式。
  2. 右击图标并选择属性。
  3. 在快捷方式选项卡上,将其用于 TARGET: C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -c 'cd'
  4. 对于 START IN,将目录/文件夹的路径放在要启动 cygwin 的位置。IEC:\some\dir\name\here

回答by Patrick Kelly

To create a Windows shortcut that launches a Cygwin terminal in a directory of your own choosing, try the following:

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

  • Right-click on the Windows desktop, select 'New', and then select 'Shortcut'.

  • For location of the item, enter the following text, changing the minttypath as needed and substituting the name of the desired directory where indicated.

    C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd /cygdrive/c/Users/Tom/Desktop/; exec bash'
    

    For example, the OP would use the following text:

    C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd DESIRED-DIRECTORY; exec bash'
    
  • Click 'Next'.

  • Enter the desired name for the shortcut and click 'Finish'.

  • 右键单击 Windows 桌面,选择“新建”,然后选择“快捷方式”。

  • 对于项目的位置,输入以下文本,mintty根据需要更改路径并在指定的位置替换所需目录的名称。

    C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd /cygdrive/c/Users/Tom/Desktop/; exec bash'
    

    例如,OP 将使用以下文本:

    @echo off
    set newpath=%cd:\=/%
    pushd "%~dp0"
    chdir bin
    bash --login -i -c "cd \"%newpath%\"; exec bash"
    
  • 点击下一步'。

  • 输入所需的快捷方式名称,然后单击“完成”。

Multiple shortcuts can be placed on the desktop to open Cygwin terminals in various often-accessed directories.

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

Inspired by solution posted on How to open a Cygwin shell at a specific directory from Netbeans?at superuser.com.

灵感来自如何在 Netbeans 的特定目录中打开 Cygwin shell 上发布的解决方案superuser.com 上

回答by Geograph

Find file Cygwin.bat and make content like this:

找到文件 Cygwin.bat 并制作如下内容:

cygwin

Add path to cygwin.bat to environment PATH.

将 cygwin.bat 的路径添加到环境 PATH。

Now in any folder you can type to address bar:

现在,您可以在任何文件夹中输入地址栏:

##代码##

Also you can type it when you in cmd.exe

您也可以在 cmd.exe 中键入它