因此,我试图更改我的 Fish shell 终端提示符,但每次我更改任何过于复杂的内容(除了颜色更改和重新排列提示符之外)时,它都会显示为空白。
我正在运行 Arch Linux。
我尝试过很多终端模拟器。白蚁、kitty、konsole、简单终端、rxvt-u、术语。普通的终端模拟器都不会显示我期望的提示。
但有一个有效的工具,即 Visual Studio Code 中的终端模拟器。
我已经尝试了尽可能多的随机不同提示,但除了 Visual Studio 代码之外,所有这些提示在任何地方都看起来是空白的。
知道如何让终端提示看起来像它应该的样子吗?
简而言之,它看起来像这样
当它应该看起来像这样的时候
继承人的内容~/.config/fish/functions/fish_prompt.fish
# name: sashimi
function fish_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -g red (set_color -o red)
set -g blue (set_color -o blue)
set -l green (set_color -o green)
set -g normal (set_color normal)
set -l ahead (_git_ahead)
set -g whitespace ' '
if test $last_status = 0
set initial_indicator "$green◆"
set status_indicator "$normal❯$cyan❯$green❯"
else
set initial_indicator "$red✖ $last_status"
set status_indicator "$red❯$red❯$red❯"
end
set -l cwd $cyan(basename (prompt_pwd))
if [ (_git_branch_name) ]
if test (_git_branch_name) = 'master'
set -l git_branch (_git_branch_name)
set git_info "$normal git:($red$git_branch$normal)"
else
set -l git_branch (_git_branch_name)
set git_info "$normal git:($blue$git_branch$normal)"
end
if [ (_is_git_dirty) ]
set -l dirty "$yellow ✗"
set git_info "$git_info$dirty"
end
end
# Notify if a command took more than 5 minutes
if [ "$CMD_DURATION" -gt 300000 ]
echo The last command took (math "$CMD_DURATION/1000") seconds.
end
echo -n -s $initial_indicator $whitespace $cwd $git_info $whitespace $ahead $status_indicator $whitespace
end
function _git_ahead
set -l commits (command git rev-list --left-right '@{upstream}...HEAD' ^/dev/null)
if [ $status != 0 ]
return
end
set -l behind (count (for arg in $commits; echo $arg; end | grep '^<'))
set -l ahead (count (for arg in $commits; echo $arg; end | grep -v '^<'))
switch "$ahead $behind"
case '' # no upstream
case '0 0' # equal to upstream
return
case '* 0' # ahead of upstream
echo "$blue↑$normal_c$ahead$whitespace"
case '0 *' # behind upstream
echo "$red↓$normal_c$behind$whitespace"
case '*' # diverged from upstream
echo "$blue↑$normal$ahead $red↓$normal_c$behind$whitespace"
end
end
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
答案1
这是 Fish 中的一个错误,是通过在不支持 unicode 的语言环境中使用非 ASCII 字符而触发的。
将您的语言环境设置为可以处理 UTF-8 的语言环境(即不是默认的“C”)