ZSH自动完成螺丝了命令名称 [英] ZSH auto-complete screws up command name

查看:210
本文介绍了ZSH自动完成螺丝了命令名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我开始做标签自动完成的命令,它让我initally旁边输入和命令变得不可读。在下面的例子中,我输入'git的车并点击标签。有一次,我选择'结账'命令提示符变为'混帐混帐车结账。该命令仍然有效,并在我的历史它的商店'混帐结账。但它的pretty恼人的视觉。反正是有改变这种行为。我想这两种不同的终端模拟器,这样我就可以确认其ZSH而不是模拟器。谢谢

截图

编辑:

回声$ ZSH_VERSION结果
4.3.10

它似乎没有用zsh的-f发生。虽然它很难说,因为唯一可行的是自动完成的目录。我使用的是'哦,我的-的zsh'这个自定义主题:

 自动加载-U附加的zsh钩
附加的zsh钩chpwd do_ls_on_chdir功能do_ls_on_chdir(){
    LS;
}功能DIRSTACK(){
OUT ='';
NUM = 1;
在$ X(迪尔斯|切-d'-f2-10);做
    OUT =$ OUT $ 1%B $ NUM:%B $ 1 $ X;
    ((NUM = NUM​​ + 1))
DONE
回声$ OUT;

}

  ZSH_THEME_GIT_PROMPT_ADDED =
ZSH_THEME_GIT_PROMPT_MODIFIED =
ZSH_THEME_GIT_PROMPT_DELETED =
ZSH_THEME_GIT_PROMPT_RENAMED =
ZSH_THEME_GIT_PROMPT_UNMERGED =
ZSH_THEME_GIT_PROMPT_UNTRACKED =ZSH_THEME_GIT_PROMPT_AHEAD =%{$ fg_bold [黄]%}↑
ZSH_THEME_GIT_PROMPT_ preFIX =
ZSH_THEME_GIT_PROMPT_SUFFIX =
ZSH_THEME_GIT_PROMPT_DIRTY =%{$ fg_bold [红色]%}✗
ZSH_THEME_GIT_PROMPT_CLEAN =%{$ fg_bold [绿色]%}✔当地user_color ='蓝'
地方回来=$ {BG [237]}
测试$ UID -eq 0安培;&安培; user_color ='红'PROMPT = $($ DIRSTACK回)
$背部%B%!%B $回到%{$ fg_bold [$ user_color]%}%〜%{$ reset_color%}'\\
'$ $回(git_prompt_status)%{$ reset_color%}'\\
'$背部%{$ fg_bold [深红]%} $(git_prompt_info)%{$ reset_color%}'\\
'$ $回(git_prompt_ahead)$ reset_color'\\
'$背部%(#>!。)​​$ reset_colorPROMPT2 =%{$ FG [红色]%}%_%{$ reset_color%}'
PROMPT3 =%{$ FG [红色]%} ...%{$ reset_color%}'
RPROMPT =%(?..%{$ fg_bold [红色]%}退出%?%{$ reset_color%})\\
%{$ FG [186]%}(%D%*)%{$ reset_color%}'

解决方案:

请注意:计算器不会让我回答我的问题,因为我问了它在过去的8小时之内。我不觉得像在等待。

所以我想通了。原来我不是正确地转义ANSI颜色codeS(我认为)。处处我在PROMPT变量有$ reset_color,我改变了这一切为%{$ reset_color%},它固定它。


解决方案

  

所以我想通了。原来我不是正确地转义ANSI颜色codeS(我认为)。处处我在PROMPT变量有$ reset_color,我改变了这一切为%{$ reset_color%},它固定它。


我才发现此链接今晚,我的提示后,搞乱 - 我总是想知道为什么的zsh的提示符示例显得那么不必要的复杂。

当您设置在的zsh 提示符的颜色,你应该逃避与%{[...]%} ,让壳知道有没有从这些序列输出和光标不动。

如果您的的逃避这个,外壳认为您的光标移动(即使它有没有)。这导致当您使用Tab补齐等方面搞砸了提示,并相当恼人的视觉效果。

下面是一些截图的没有的逃脱重设色提示序列( PR_NO_COLOUR =%{$的terminfo [sgr0 ]%},在我的提示设置)。正如我们所看到的,光标开始在错误的地方:

这里要:

和试图逃逸无制表完成后,提示都是困惑在哪里文字,并在光标应放在:

(光标应放置在目录的末尾,不中途)。

所以提示顺序是这样的:

  PS1 =%{$ FG [红色]%}%N%{$ reset_color%} @%{$ FG [蓝]%}%M%{$ FG [黄]%}%〜%{$ reset_color%} %%

,因为一切都在里面很好逃脱%{...%} 对。

When I start doing tab auto-complete of a command, it keeps what I initally typed next to it and the command becomes unreadable. In the example below, I typed 'git che' and hit tab. Once I select 'checkout' the command prompt becomes 'git che git checkout'. The command still works and in my history it stores 'git checkout'. But its pretty annoying visually. Is there anyway to change this behavior. I tried this in 2 different terminal emulators, so I can confirm its ZSH and not the emulator. Thanks

Screenshot

EDIT:

echo $ZSH_VERSION
4.3.10

It doesnt seem to happen with zsh -f. Though its hard to tell since the only autocomplete that works is directories. I'm using 'oh-my-zsh' with this custom theme:

autoload -U add-zsh-hook
add-zsh-hook chpwd do_ls_on_chdir

function do_ls_on_chdir() {
    ls; 
}

function dirStack(){
OUT='';
NUM=1;
for X in $(dirs | cut -d ' ' -f2-10); do
    OUT="$OUT$1%B$NUM:%b$1$X ";
    (( NUM=NUM+1 ))
done
echo $OUT;

}

ZSH_THEME_GIT_PROMPT_ADDED=""
ZSH_THEME_GIT_PROMPT_MODIFIED=""
ZSH_THEME_GIT_PROMPT_DELETED=""
ZSH_THEME_GIT_PROMPT_RENAMED=""
ZSH_THEME_GIT_PROMPT_UNMERGED=""
ZSH_THEME_GIT_PROMPT_UNTRACKED=""

ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_bold[yellow]%}↑"
ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg_bold[red]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg_bold[green]%}✔"

local user_color='blue'
local back="${BG[237]}"
test $UID -eq 0 && user_color='red'

PROMPT='$(dirStack $back)
$back%B%!%b$back %{$fg_bold[$user_color]%}%~%{$reset_color%}'\
'$back $(git_prompt_status)%{$reset_color%}'\
'$back%{$fg_bold[magenta]%}$(git_prompt_info)%{$reset_color%}'\
'$back$(git_prompt_ahead)$reset_color'\
'$back%(!.#.>)$reset_color '

PROMPT2='%{$fg[red]%}%_ %{$reset_color%}'
PROMPT3='%{$fg[red]%}... %{$reset_color%}'
RPROMPT='%(?..%{$fg_bold[red]%}exit %?%{$reset_color%})'\
' %{$FG[186]%}(%D %*)%{$reset_color%}'

SOLUTION:

NOTE: stackoverflow wont let me answer my own question since I asked it within the past 8 hours. I dont feel like waiting.

So I figured it out. It turns out I wasnt properly escaping the ANSI color codes (I think). Everywhere I had $reset_color in my PROMPT variable, I changed that to %{$reset_color%} and it fixed it.

解决方案

So I figured it out. It turns out I wasnt properly escaping the ANSI color codes (I think). Everywhere I had $reset_color in my PROMPT variable, I changed that to %{$reset_color%} and it fixed it.

I only discovered this link tonight, after messing with my prompt - I'd always wondered why the ZSH prompt examples seemed so needlessly complex.

When you set up the colors in your zsh prompt, you should escape things with %{ [...] %}, so that 'the shell knows there is no output from these sequences and the cursor hasn't moved'.

If you don't escape this, the shell believes that your cursor has moved (even though it hasn't). This leads to messed up prompts, and rather annoying visual effects when you use tab-completion etc.

Here's some screenshots without escaping the reset-color prompt sequence (PR_NO_COLOUR="%{$terminfo[sgr0]%}", in my prompt settings). As we can see, the cursor starts in the wrong place:

It should be here:

And after trying tab-completion without escaping, the prompt is all confused about where the text is, and where the cursor should be placed:

(The cursor should be placed at the end of the directory, not halfway through).

So the prompt sequences look like this:

PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "

because everything has to be escaped nicely inside %{...%} pairs.

这篇关于ZSH自动完成螺丝了命令名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆