powshell获得在zsh上的git插件的效果,获取智能提示

65 阅读1分钟

有时候用命令行操作git的时候可能会突然忘记分支名称,又或者是忘记命令的参数有哪些这个时候 安装posh-git就可以像oh-my-zsh预装的git创建那样按tab获得提示 效果

post-git

image.png

image.png

安装

Install-Module posh-git

使用 使用你熟悉的编辑器在powshell的配置文件中导入

code $PROFILE
#or 
vi $PROFILE

插入以下

Import-Module posh-git

更多配置还是直接看posh-git的文档吧

推荐使用powshell 7.x的版本,区别于系统自带的5.x,它需要额外安装

还有一些额外的有意思的实用配置

输入时的智能补全预测 image.png

按下tab之后显示可选的菜单选项

image.png

# 让powshell支持vim的操作方式
Set-PSReadLineOption -EditMode Vi
# 设置智能提示补全预测的的源
Set-PSReadLineOption -PredictionSource History
# TAB补全时提供可选择菜单
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
# 方向右键补全历史提示  
Set-PSReadLineKeyHandler -Key "RightArrow" -Function ForwardWord

# 切换vim的输入模式的时候切换光标样式
function OnViModeChange {
    if ($args[0] -eq 'Command') {
        # Set the cursor to a blinking block.
        Write-Host -NoNewLine "`e[1 q"
    } else {
        # Set the cursor to a blinking line.
        Write-Host -NoNewLine "`e[5 q"
    }
}

Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange