Arch-Linux

終端魚提示空白

  • April 24, 2020

所以我試圖改變我的fish shell終端提示,但每次我改變任何太複雜的東西(除了顏色變化和重新排列提示),它都會變成空白。

我正在執行 Arch Linux。

我試過很多終端模擬器。白蟻,小貓,konsole,簡單終端,rxvt-u,術語。沒有一個普通的終端模擬器會顯示我期望的提示。

但是有一個有效的,Visual Studio 程式碼中的終端仿真器。

我已經嘗試了盡可能多的隨機不同提示,但除了 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

這是 fish 中的一個錯誤,它是通過使用非 ASCII 字元和不支持 unicode 的語言環境觸發的。

將您的語言環境設置為可以處理 UTF-8 的內容(即不是預設的“C”)

引用自:https://unix.stackexchange.com/questions/582287