7

Powershell 在提示符中显示 git 分支信息

 2 years ago
source link: https://www.lfhacks.com/tech/+powershell-prompt-git-branch
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.

Powershell 在提示符中显示 git 分支信息

扫一扫,用手机分享 qr.php?VnVZaQc6WyhTcVEgA3MLYAZ5V3gAeVtyUHcAJlVvB2cFOwBsBzFQPAciVHtVNVFvATxTfFIoCzBVZglpB34CL1ZwWTsHJVs5U3dRIwNoCz8GOlc7ACNbdVByAGdVbgdxBScAIAc1UD4HJVR4VTRRcgEwUz1SPws9VSMJdQdsAjVWNllnB2JbbFM1UWEDMgttBmA%3D
1552.jpg

PowerShell 自带的提示符不够美观,影响工作效率。本文介绍一种自定义 PowerShell 命令提示符中填入 git 分支的方法。

具体的作法另开一篇单独介绍。

function Prompt {
	$is_git = ""
	git rev-parse | Out-Null

	if($?){
		$git_branch = " $(git branch --show-current --no-color)"
	}

    $pattern = $env:userprofile -replace '\\', '\\'
    $promptString = "$(Get-Location)" -replace $pattern, "~"
    "`e[1;32m" + $promptString +"`e[1;36m"+ $git_branch + "`e[m "
}

坚持原创不易。如果您觉得有收获,请考虑资助本站,以期待更多原创文章。

打赏作者,支持小站

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK