Powerline Go用 Go 编写的低延迟 Shell 提示

联合创作 · 2023-09-30 11:44

用于 shell 且具有 Powerline 样式的提示




  • 显示关于 git/hg 分支的一些重要细节


  • 如果最后一个命令以失败代码退出,则更改颜色


  • 如果对目录树过于深入,请使用省略号缩短显示的路径


  • 显示当前的 Python virtualenv 环境


  • 使用 rbenv 显示当前的 Ruby 版本


  • 显示您是否在 nix shell 中


  • 很容易定制和扩展



安装


需要 Go 1.12+


powerline-go使用 ANSI 颜色代码,但是可能需要将 $TERM 设置为xterm-256color才能工作。


预编译的二进制文件


在 release 选项卡中为 x64 Linux 和 macOS 提供了预编译的二进制文件


其他平台



  • 安装(和更新)包




go install github.com/justjanne/powerline-go@latest



  • 默认情况下它将在 $GOPATH/bin中,如果想更改它,可以设置$GOPATH和/或$GOBIN,但也需要更改以下脚本中的路径。


Bash


将以下内容添加到.bashrc中(Mac 上为.profile):




function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -error $? -jobs $(jobs -p | wc -l))"

# Uncomment the following line to automatically clear errors after showing
# them once. This not only clears the error for powerline-go, but also for
# everything else you run in that shell. Don't enable this if you're not
# sure this is what you want.

#set "?"
}

if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi


目前,使用 bash 时不支持右键提示。


ZSH


将以下内容添加到.zshrc:




function powerline_precmd() {
PS1="$($GOPATH/bin/powerline-go -error $? -jobs ${${(%):%j}:-0})"

# Uncomment the following line to automatically clear errors after showing
# them once. This not only clears the error for powerline-go, but also for
# everything else you run in that shell. Don't enable this if you're not
# sure this is what you want.

#set "?"
}

function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}

if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
install_powerline_precmd
fi


Fish


重新在~/.config/fish/config.fish定义fish_prompt




function fish_prompt
eval $GOPATH/bin/powerline-go -error $status -jobs (count (jobs -p))
end

浏览 23
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报