修复 powerline-shell bash 提示(模式:“兼容”或模式:“修补”)

修复 powerline-shell bash 提示(模式:“兼容”或模式:“修补”)

背景

我有问题powerline-shell提示;由于某种原因,我找不到任何方法来构建图形>电力线角色。

我使用以下命令安装了 python powerline json 配置:

$ mkdir -p ~/.config/powerline-shell && \
powerline-shell --generate-config > ~/.config/powerline-shell/config.json

顺便说一下,我使用 putty 通过 ssh 进入我的系统。无论我设置$TERMxterm-256color还是 ,putty电力线提示渲染都没有区别。


我的~/.config/powerline-shell/config.json内容...

显然,此配置用于mode: flat解决>渲染问题。

$  cat ~/.config/powerline-shell/config.json

{
  "mode": "flat",
  "segments": [
    "virtual_env",
    "aws_profile",
    "ssh",
    "cwd",
    "git",
    "git_stash",
    "jobs",
    "set_term_title",
    "svn",
    "newline",
    "root"
  ],
  "cwd": {
    "mode": "flat"
  },
  "theme": "default"
}

渲染powerline-shell模式:平面

当我使用时"mode": "flat",~/.config/powerline-shell/config.json提示看起来很好...应该注意flat提示模式不使用图形>字符......

powerline_with_mode_flat


渲染powerline-shell模式:兼容

当我在 中使用"mode": "patched"或时,"mode": "compatible"~/.config/powerline-shell/config.json图形>字符是必需的,但似乎不存在(请参阅底部的注释)

powerline_with_mode_patched


问题

我该如何修复此powerline-shell提示安装以使用mode: compatiblepatched

我安装了一个中心powerline-shell脚本,每次使用时/opt/bin/powerline-shell都会以完整路径调用该脚本。/opt

我的.bashrc内容...

$ cat ~/.bashrc

# .bashrc - Always executed for a new shell, unlike .bash_profile,
#           which normally isn't run for terms without the -ls option

export PYTHON_CONFIGURE_OPTS="--enable-shared"

# I built a custom vim-9.0 in /opt/vim90
export VIMRUNTIME="/opt/vim90/runtime/"

# Run a whois query that retrieves info from Team CYMRU about an IP
function cwhois_fn {
    whois -h whois.cymru.com " -v $1"
}

# Use vi for term line edits
set -o vi


## Bash history hacks
##  http://unix.stackexchange.com/a/48116/6766
HISTSIZE=2000
HISTFILESIZE=$HISTSIZE
HISTCONTROL=ignorespace:ignoredups
HISTTIMEFORMAT="%y-%m-%d %T "
#function history {
#  _bash_history_sync
#  builtin history "$@"
#}
function _bash_history_sync {
  builtin history -a         #1
  HISTFILESIZE=$HISTSIZE     #2
  builtin history -c         #3
  builtin history -r         #4
}
export PROMPT_COMMAND=_bash_history_sync

export TERM="xterm-256color"

# Set a default bash prompt...
#PS1='[\u@\h \W]\$ '

function _update_ps1() {
    PS1=$(/opt/bin/powerline-shell $?)
}

#if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]
then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
    export PROMPT_COMMAND
else
    export PS1='[\u@\h \W]\$ '
    export PROMPT_COMMAND="$PS1"
fi

export PS1 HISTFILESIZE HISTTIMEFORMAT HISTCONTROL HISTSIZE

# Get the LOCAL aliases and functions
if [ -f ~/.bashrc.local ]; then
        . ~/.bashrc.local
fi

###############################################################################
#
# Use the following to initialize Debian for powerline installation...
#    > sudo apt-get install fonts-powerline
#    > sudo apt-get install fonts-hack
#    > sudo apt-get install powerline
#
# Use the following to install under Debian...
#    https://github.com/b-ryan/powerline-shell
#    > git clone https://github.com/ryanoasis/nerd-fonts
#    > cd nerd-fonts
#    > rm -rf .git      # the .git directory is massive!
#    > ./install.sh
#
# Use the following to initialize MacOS for the powerline installation...
#    https://github.com/b-ryan/powerline-shell
#    > brew tap homebrew/cask
#    > brew install fontforge
#    > git clone https://github.com/ryanoasis/nerd-fonts
#    > cd nerd-fonts
#    > rm -rf .git        # the .git directory is massive!
#    > ./install.sh
#
###############################################################################

/opt/bin/powerline-shell内容...

#!/opt/virtual_env/py39_test/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from powerline_shell import main as powerline_main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(powerline_main())

答案1

我在 Debian 11 系统上使用mode: patched(参考下文)实现了这个功能......~/.config/powerline-shell/config.json

  • 具体命令...
    • sudo apt-get install fonts-powerline fonts-hack powerline
    • pip install powerline-shell
    • git clone https://github.com/ryanoasis/nerd-fonts; cd nerd-fonts; rm -rf .git; install.sh; # install.sh installs the nerd-fonts
    • 我的~/.bashrc添加/更改:
function _update_ps1() {
    # /opt/bin/powerline-shell should be manually-installed
    #     see the script at the bottom of this superuser answer
    PS1=$(/opt/bin/powerline-shell $?)
}

export TERM="xterm-256color"

if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]
then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
    export PROMPT_COMMAND
else
    export PS1='[\u@\h \W]\$ '
    export PROMPT_COMMAND="$PS1"
fi
  • 我的内容~/.config/powerline-shell/config.json
{
  "mode": "patched",
  "segments": [
    "virtual_env",
    "aws_profile",
    "ssh",
    "cwd",
    "git",
    "git_stash",
    "jobs",
    "set_term_title",
    "svn",
    "newline",
    "root"
  ],
  "cwd": {
    "mode": "patched"
  },
  "theme": "default"
}
  • 我的内容/opt/bin/powerline-shell
#!/opt/virtual_env/py39_test/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from powerline_shell import main as powerline_main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(powerline_main())

相关内容