【问题标题】:zsh custom theme, command completion bugzsh 自定义主题,命令补全bug
【发布时间】:2021-09-12 20:11:43
【问题描述】:

我正在制作我自己的自定义 zsh 主题,除了命令自动完成之外,一切正常。 当我按 Tab 自动完成我的命令时,它让我写的内容在复制初始输入后自动完成

$cat .oh-my-zsh/custom/theme/leslie.zsh-theme

function get_pwd() {
  echo "${PWD/$HOME/~}"
}

function get_branch(){
  if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then 
   echo -n "[$(git branch --show-current)]"
  else
  fi
}

function put_spacing() {
  local termwidth  
  (( termwidth =  ${COLUMNS} - ${#$(get_pwd)} -11 - ${#user}  -  ${#$(get_branch)} ))
  local spacing=""
  for i in {1..$termwidth}; do
    spacing="${spacing} "
  done
  echo $spacing
}

local user=%n

PROMPT="%B%(?:$FG[128] :$FG[160] )"
PROMPT+='$fg[cyan][$user]%b:  $fg[cyan]$(get_pwd)$reset_color$(put_spacing)%B$FG[128]$(get_branch)%b'
PROMPT+="%(?:$FG[128]:$FG[160])⮑  %{$reset_color%}"


$cat .zshrc

export ZSH="/Users/leslie/.oh-my-zsh"
ZSH_THEME="leslie"
plugins=(git)
source $ZSH/oh-my-zsh.sh

我的错误:

 [leslie]:  ~                                                              
⮑  cd D           cd Desktop/

My Bug in picture

【问题讨论】:

    标签: shell autocomplete zsh customization


    【解决方案1】:
    function get_pwd() {
      echo "${PWD/$HOME/~}"
    }
    
    function get_branch(){
      if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then 
       echo -n "[$(git branch --show-current)]"
      else
      fi
    }
    
    function put_spacing() {
      local termwidth  
      (( termwidth =  ${COLUMNS} - ${#$(get_pwd)} -11 - ${#user}  -  ${#$(get_branch)} ))
      local spacing=""
      for i in {1..$termwidth}; do
        spacing="${spacing} "
      done
      echo $spacing
    }
    
    local user=%n
    
    PROMPT="%B%(?:$FG[128] :$FG[160] )"
    PROMPT+='$fg[cyan][$user]%b:  $fg[cyan]$(get_pwd)%{$reset_color%}$(put_spacing)%B$FG[128]$(get_branch)%b
    %(?:$FG[128]:$FG[160])⮑  %{$reset_color%}'
    
    

    删除最后一个 PROMT+= 解决了我的问题,如果有人有解释我会很高兴听到它。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-09
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 2012-04-09
      相关资源
      最近更新 更多