4

在 vscode 默认终端 PowerShell 快速打开当前路径下的 Git Bash 窗口

 2 years ago
source link: https://hellodk.cn/post/933
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

2022-03-03 update

为 PowerShell 设置 alias 然后可以直接输入 gitbash 打开当前路径下的 Git Bash 窗口。


vscode 默认终端是 PowerShell,当然了这个可以更改,可以改成 Windows Terminal、Git Bash 等终端,但这不属于本文讨论范围。

PowerShell 没有 touch 等等 Linux 下的命令,平常通过 PS 使用 git 我表示不太好用,于是有了本文。

编写文件 d:\git-bash.bat,文件内容如下

@echo off
rem open Git Bash in current dir from vscode default terminal PowerShell
rem author: hellodk
rem time: 2022-03-02 17:01:52
set "CURRENT_DIR=%cd%"
start /d "C:\Program Files\Git" git-bash.exe --cd="%CURRENT_DIR%"

使用简单的 dos 语法即可实现这个需求。将当前路径存入 CURRENT_DIR 变量,使用 start 命令,/d 参数(打开指定路径下的文件/程序),--cd= 可以指定打开时的 dir. 更多请查看: How do I change the default location for Git Bash on Windows?

使用 vscode 打开一个项目,按下 Ctrl + Shift + `,输入 d:\git-bash.bat(可以tab自动补全) 回车即可打开。

动图演示如下
8185137c670ec31ac9e97e5211eccde3.gif

文章目录

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK