如何使用脚本启动具有特定工作目录的Git Bash窗口? [英] How do I launch a Git Bash window with particular working directory using a script?

查看:106
本文介绍了如何使用脚本启动具有特定工作目录的Git Bash窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用脚本(Bash或Windows批处理)启动具有指定工作目录的新Git Bash窗口?

How can I launch a new Git Bash window with a specified working directory using a script (either Bash or Windows batch)?

我的目标是从一个脚本启动多个Git Bash窗口,每个窗口都设置到不同的工作目录.这样,我可以在启动计算机后快速开始工作,而不必打开Git Bash窗口并将每个窗口导航到正确的工作目录.

My goal is to launch multiple Git Bash windows from a single script, each set to a different working directory. This way I can quickly get to work after booting the computer instead of having to open Git Bash windows and navigating each one to the correct working directory.

我没有问如何更改默认工作目录,例如

I am not asking how to change the default working directory, like this question does, but to launch one or more terminal windows with different working directories from a script.

推荐答案

Git Bash将cmd.exe用于其终端,以及sh.exe(一种cmd.exe包装器)提供的MSYS/MinGW的扩展.在Windows中,您可以使用start命令启动新终端.

Git Bash uses cmd.exe for its terminal plus extentions from MSYS/MinGW which are provided by sh.exe, a sort of cmd.exe wrapper. In Windows you launch a new terminal using the start command.

因此启动具有特定工作目录的新Git Bash终端的shell脚本是:

Thus a shell script which launches a new Git Bash terminal with a specific working directory is:

(cd C:/path/to/dir1 && start sh --login) &
(cd D:/path/to/dir2 && start sh --login) &

等效的Windows批处理脚本是:

An equivalent Windows batch script is:

C:
cd \path\to\dir1
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login 
D:
cd \path\to\dir2
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login 

要获得与从开始菜单启动的Git Bash相同的字体和窗口大小,最简单的方法是将开始菜单快捷方式设置复制到命令控制台的默认设置(要更改默认设置,请打开cmd.exe,然后单击鼠标左键.左上角的图标,然后选择默认值.

To get the same font and window size as the Git Bash launched from the start menu, it is easiest to copy the start menu shortcut settings to the command console defaults (to change defaults, open cmd.exe, left-click the upper left icon, and select Defaults).

这篇关于如何使用脚本启动具有特定工作目录的Git Bash窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆