windows cygwin + console2:使用启动目录运行 cygwin bash
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3813205/
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
cygwin + console2: running cygwin bash with startup dir
提问by crispy
I am using Console2 as a bash wrapper on Windows. Most importantly, it enables me to start up a new bash tab in a predefined project directory.
我在 Windows 上使用 Console2 作为 bash 包装器。最重要的是,它使我能够在预定义的项目目录中启动一个新的 bash 选项卡。
Now I would like to replace the Windows command line by a Cygwin bash. However, the "Startup Dir" setting in Console2 is not respected by Cygwin.
现在我想用 Cygwin bash 替换 Windows 命令行。但是,Cygwin 不遵守 Console2 中的“启动目录”设置。
Basically, I see three solution approaches:
基本上,我看到了三种解决方法:
- Figure out how the Console2 setting has to look likeso that the Cygwin bash respects it
- Add a startup parameterto the Cygwin bash, setting the startup directory
- Automatically run a script after bash startupthat changes the directory
- 弄清楚Console2 设置的外观如何,以便 Cygwin bash 尊重它
- Cygwin bash添加启动参数,设置启动目录
- 在 bash 启动后自动运行更改目录的脚本
Searching around in Cygwin's documentation and the rest of the Internet, I could not find a solution to any of those approaches. I could imagine that the solution is trivial to someone else, though. :)
在 Cygwin 的文档和 Internet 的其余部分中搜索,我找不到任何这些方法的解决方案。不过,我可以想象该解决方案对其他人来说是微不足道的。:)
environment: Win XP, Console 2.00.146, Cygwin 1.7.7, GNU Bash 3.2.51(24)
环境:Win XP、控制台 2.00.146、Cygwin 1.7.7、GNU Bash 3.2.51(24)
回答by Paused until further notice.
As for the last bullet point, edit your ~/.bashrc
and add a cd
command at the end.
至于最后一个要点,编辑你的~/.bashrc
并在最后添加一个cd
命令。
Instead of that, you can try this for your first bullet point: If your Console2 configuration to start Bash looks something like this:
取而代之的是,您可以在第一个要点中尝试此操作:如果用于启动 Bash 的 Console2 配置如下所示:
bash --login -i
change it to:
将其更改为:
bash --login -i -c 'cd somdir; exec bash'
回答by zen
I was having the same problem, saw your post, and then found this answer:
我遇到了同样的问题,看了你的帖子,然后找到了这个答案:
- Run the Setup.exe Cygwin installer and add the "chere" package
- In Console2, add a new tab called "Bash" with a shell path of "C:\cygwin\bin\bash". See screenshot.
- Finally, add the following to the registry: Code:
- 运行 Setup.exe Cygwin 安装程序并添加“chere”包
- 在 Console2 中,添加一个名为“Bash”的新选项卡,其 shell 路径为“C:\cygwin\bin\bash”。见截图。
- 最后,将以下内容添加到注册表中: 代码:
Windows Registry Editor Version 5.00
Windows 注册表编辑器 5.00 版
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...]
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin 这里...]
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...\command] @="\"C:\Program Files\Console2\Console.exe\" -t Bash -r \"/bin/xhere /bin/bash.exe '%L'\""
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...\command] @="\"C:\Program Files\Console2\Console.exe\" -t Bash -r \"/bin/xhere /bin/bash. exe '%L'\""
Found this solution at: http://www.e-texteditor.com/forum/viewtopic.php?p=8884
在以下位置找到此解决方案:http: //www.e-texteditor.com/forum/viewtopic.php?p=8884
回答by Dmitry Oksenchuk
- In Cygwin installer add "chere" package (contains /bin/xhere script)
- Use the following shell command in Console2 settings:
C:\cygwin\bin\bash.exe -c '/bin/xhere /bin/bash'
- 在 Cygwin 安装程序中添加“chere”包(包含 /bin/xhere 脚本)
- 在 Console2 设置中使用以下 shell 命令:
C:\cygwin\bin\bash.exe -c '/bin/xhere /bin/bash'
回答by Martin Lütke
I had some problems with some with the approaches above (Console2 window screwed up when using c:\cygwin\bin\bash.exe as shell, xhere not reflecting my actual working dir).
我在使用上述方法时遇到了一些问题(使用 c:\cygwin\bin\bash.exe 作为 shell 时,控制台 2 窗口搞砸了,xhere 没有反映我的实际工作目录)。
So I created this batch file and used it as Console2's shell:
所以我创建了这个批处理文件并将其用作 Console2 的 shell:
C:\cygwin64\cygbash.bat:
C:\cygwin64\cygbash.bat:
C:\cygwin64\bin\bash --login -i -c "/bin/xhere /bin/bash `cygpath -d '%CD%'`"
回答by Kelly
I tried variations of all the above, but none worked. This is what worked for me using Console2 v2.00.148:
我尝试了上述所有方法的变体,但都没有奏效。这就是使用 Console2 v2.00.148 对我有用的方法:
1)..Copy the Cygwin.bat to a new file: Cygbash.bat.
1)..将 Cygwin.bat 复制到一个新文件:Cygbash.bat。
2)..Replace the last line to be this: bash --login -i -c 'cd /cygdrive/c/; exec bash'
2)..将最后一行替换为: bash --login -i -c 'cd /cygdrive/c/; exec bash'
3)..Go into Console2 settings and change the shell to point to this new Cygbash.bat file.
3)..进入Console2设置并将shell更改为指向这个新的Cygbash.bat文件。
The above will start Console2 in the root of your C drive. fyi - I'm the original poster, just forgot to login to my account first.
以上将在你的 C 驱动器的根目录中启动 Console2。仅供参考 - 我是原始海报,只是忘记先登录我的帐户。
回答by kerl
Change the shell dir to:
bash --login -i -c 'cd /cygdrive/c/...; exec /bin/bash'
Add this line to the end of
C:\cygwin\home\USERNAME\.profile
cd -
将 shell 目录更改为:
bash --login -i -c 'cd /cygdrive/c/...; exec /bin/bash'
将此行添加到末尾
C:\cygwin\home\USERNAME\.profile
cd -
回答by Hugo
Regarding your last bullet point, you can put for example:
关于您的最后一个要点,您可以输入例如:
cd /cygdrive/d
in ~/.bash_profile This will be picked up when using Console2 and also when you run Cygwin itself.
在 ~/.bash_profile 中,这将在使用 Console2 以及运行 Cygwin 时获取。