如何在 Windows 中的目前位置開啟新的 git bash 終端機視窗?

如何在 Windows 中的目前位置開啟新的 git bash 終端機視窗?

Alt運行 git bash 時,我可以使用+在根目錄中開啟一個新的 bash 窗口F2

我可以在目前目錄路徑開啟Windows資源管理器視窗

$ explorer .

$ sh

在我的位置打開一個新的終端視窗只需返回

sh: __git_ps1: command not found

並在目前視窗中開啟 shell,而不運行 git。

如何在我的位置快速開啟新的 bash shell?

答案1

StuperUser 的答案是正確的,但我想補充一點,除了在 PATH 環境中添加 shell 腳本之外,還可以在.bashrc.bash_profile文件中添加一個簡單的 bash 別名。

只需建立別名:

alias git-bash='/git-bash.exe & > /dev/null 2&>1'

bashrc 和 bash_profile 是標準的 BASH 設定文件,您可以在使用者主資料夾中找到它們。

更多資訊Bash 啟動文件

答案2

由於這是專門針對 git-bash 終端的,因此請將 Git 目錄 (C:\Program Files\Git) 新增到您的路徑 (https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/

然後運行

$ git-bash

在目前位置開啟一個新的 git-bash。

但為了避免阻塞目前終端,有必要使用& > /dev/null 2&>1在背景運行並將結果透過管道傳輸到 null(請參閱https://superuser.com/a/1314830/641),所以將指令加入目錄下的一個.sh中,方便呼叫。

答案3

我知道這已經是幾年前的事了,但我還是想發布這個。

當我使用@Alex 的答案時,似乎每個視窗都透過連結進程或其他方式連接到另一個視窗。這是我針對從目前位置開始的完全獨立的新視窗的解決方案。

alias new='start "" "C:\Program Files\Git\git-bash.exe"'

每次使用時都會出現一個新視窗。但我實際上喜歡打開 4 個終端,因此我通常使用以下別名在當前位置打開 3 個新的終端視窗:

alias new3='start "" "C:\Program Files\Git\git-bash.exe" && start "" "C:\Program Files\Git\git-bash.exe" && start "" "C:\Program Files\Git\git-bash.exe"'

乾杯!

答案4

設定環境變數指向 git location C:\Program Files\Git

現在轉到 Windows 中您想要開啟 git bash 的位置。

按下alt + d並鍵入get-bash,您就可以開始了。

相關內容