编辑命令行提示符 prompt,支持显示 git 分支、标签等信息

实时在
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 (
        # 命令执行失败
        $? 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值