bash tab 自动完成太慢,但 teraterm 或 putty 却没有这个问题

bash tab 自动完成太慢,但 teraterm 或 putty 却没有这个问题

我正在使用 Ubuntu 18.04,当我按下 Tab 按钮进行自动完成时,它卡在了 1~2 秒内。

我一直在尝试解决这个问题,但没能解决。我甚至换了一台新电脑,但问题依然存在。

奇怪的是,当我通过其他电脑上的 ssh 连接我的 ubuntu(使用 teraterm 或 putty 或其他电脑的 ubuntu)时,问题消失并且运行良好。

我不知道为什么。。可能是网络问题吗?我的 ubuntu 电脑在防火墙和代理后面,但我旁边公司的 ubuntu 运行良好。

您觉得有什么可疑吗?

以下是我针对此问题所采取的措施

  • 更换新的电脑。
  • sudo updatedb
  • sudo apt install --reinstall bash-completion

我跟着https://unix.stackexchange.com/a/185960方法来调查这个问题。但是,当我按下 之后的 tab 按钮时set -x,它卡在了第一个位置。我的意思是,

$ set -x
$ ls a<tab>
# got stuck like 2~3 second
output of `set -x`

# full output when I push tab with `set -x`
+ _init_completion -s
+ local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -s
+ case $flag in
+ split=false
+ exclude+==
+ getopts n:e:o:i:s flag -s
+ COMPREPLY=()
+ local 'redir=@(?([0-9])<|?([0-9&])>?(>)|>&)'
+ _get_comp_words_by_ref -n '=<>&' cur prev words cword
+ local exclude flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur vcword vprev vwords
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ case $flag in
+ exclude='=<>&'
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ [[ 6 -ge 3 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ let 'OPTIND += 1'
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ let 'OPTIND += 1'
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ let 'OPTIND += 1'
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ let 'OPTIND += 1'
+ [[ 6 -ge 7 ]]
+ __get_cword_at_cursor_by_ref '=<>&' words cword cur
+ words=()
+ local cword words
+ __reassemble_comp_words_by_ref '=<>&' words cword
+ local exclude i j line ref
+ [[ -n =<>& ]]
+ exclude='=<>&'
+ printf -v cword %s 1
+ [[ -n =<>& ]]
+ line='ls '
+ (( i=0, j=0 ))
+ (( i < 2 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ printf -v 'words[0]' %s ls
+ line=' '
+ [[ 0 == 1 ]]
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 1 -gt 0 ]]
+ [[ '' == +([=<>&]) ]]
+ ref='words[1]'
+ printf -v 'words[1]' %s ''
+ line=' '
+ [[ 1 == 1 ]]
+ printf -v cword %s 1
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 2 == 1 ]]
+ local i cur index=3 'lead=ls '
+ [[ 3 -gt 0 ]]
+ [[ -n ls  ]]
+ [[ -n ls ]]
+ cur='ls '
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 3 -ge 2 ]]
+ [[ ls != \l\s ]]
+ [[ 0 -lt 1 ]]
+ local old_size=3
+ cur=' '
+ local new_size=1
+ index=1
+ (( ++i  ))
+ (( i <= cword ))
+ [[ 1 -ge 0 ]]
+ [[ '' != '' ]]
+ [[ 1 -lt 1 ]]
+ (( ++i  ))
+ (( i <= cword ))
+ [[ -n   ]]
+ [[ ! -n '' ]]
+ cur=
+ [[ 1 -lt 0 ]]
+ local words cword cur
+ _upvars -a2 words ls '' -v cword 1 -v cur ''
+ ((  10  ))
+ ((  10  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  6  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  3  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=
+ shift 3
+ ((  0  ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v $vcur "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v $vcword "$cword")
+ [[ -n prev ]]
+ [[ 1 -ge 1 ]]
+ upvars+=("$vprev")
+ upargs+=(-v $vprev "${words[cword - 1]}")
+ [[ -n words ]]
+ upvars+=("$vwords")
+ upargs+=(-a${#words[@]} $vwords "${words[@]}")
+ ((  4  ))
+ local cur cword prev words
+ _upvars -v cur '' -v cword 1 -v prev ls -a2 words ls ''
+ ((  13  ))
+ ((  13  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=
+ shift 3
+ ((  10  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  7  ))
+ case $1 in
+ [[ -n prev ]]
+ unset -v prev
+ eval 'prev="$3"'
++ prev=ls
+ shift 3
+ ((  4  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  0  ))
+ _variables
+ [[ '' =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]
+ [[ '' =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
+ [[ '' =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*]$ ]]
+ case $prev in
+ return 1
+ [[ '' == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ [[ ls == @(?([0-9])<|?([0-9&])>?(>)|>&) ]]
+ local i skip
+ (( i=1 ))
+ (( i < 2 ))
+ [[ '' == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=2
+ (( 1 ))
+ (( i < 2 ))
+ [[ 1 -le 0 ]]
+ prev=ls
+ [[ -n false ]]
+ _split_longopt
+ [[ '' == --?*=* ]]
+ return 1
+ return 0
+ case "${prev,,}" in
+ false
+ [[ '' == -* ]]
+ [[ ls == @(rmdir|chroot) ]]
+ [[ ls == mkdir ]]
+ _filedir
+ local 'IFS=
'
+ _tilde ''
+ local result=0
+ [[ '' == \~* ]]
+ return 0
+ local -a toks
+ local x tmp
++ compgen -d -- ''
+ x=
+ [[ '' != -d ]]
+ local quoted
+ _quote_readline_by_ref '' quoted
+ '[' -z '' ']'
+ printf -v quoted %s ''
+ [[ '' == *\\* ]]
+ [[ '' == \$* ]]
+ local xspec=
++ compgen -f -X '' --
+ x=
+ [[ -n '' ]]
+ [[ 0 -ne 0 ]]

这是我的电脑信息。

$ uname -a
Linux seongwoo 5.4.0-72-generic #80~18.04.1-Ubuntu SMP Mon Apr 12 23:26:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

虽然我正在使用 oh-my-zsh,但当我使用时也遇到了同样的问题exec /bin/bash

答案1

我终于找到答案了!!

为了解决这个问题,请关闭终端的“终端铃声”选项。

在终端,

编辑 > 首选项 > 声音 > 终端铃声

相关内容