实时在
Linhieng/current–Microsoft.PowerShell_profile.ps1 上更新
打开 $Profile 文件,将下面内容粘贴到其中即可:
<# 负责打印 git 分支相关信息
支持输出以下信息:
当前分支,或者是 hash 值
当前目录是否为 git 子目录
当前是否有提交历史
#>
function write_host_git_branch {
# 在这里,能确保是一个 git 仓库,或者是一个 git 仓库中的子目录
# 获取当前 HEAD 所在分支名。如果当前是 detached HEAD 状态,则显示为 hash。
$git_branch = git symbolic-ref --short --quiet HEAD
Write-Host "(" -ForegroundColor "DarkGray" -NoNewline
if ( $null -eq $git_branch ) {
$hash = git rev-parse --short HEAD
Write-Host $hash -ForegroundColor "red" -NoNewline
} else {
Write-Host $git_branch -ForegroundColor "blue" -NoNewline
}
Write-Host ") " -ForegroundColor "DarkGray" -NoNewline
if (
# 如果当前目录没有 .git 文件夹,说明当前是在 git 仓库的子目录
$false -eq (Test-Path .git)
) {
Write-Host "sub " -ForegroundColor "DarkGray" -NoNewline
}
$git_log = git log 2>&1
if (
# 命令执行失败
$?

3594

被折叠的 条评论
为什么被折叠?



