AOSC-Dev/bash-pinyin-completion-rs

在wsl(debian)以及msys2中使用会闪退

Closed this issue · 6 comments

在wsl(debian)以及msys2中使用会闪退

在msys中
_comp_compgen__call_builtin 改为_comp_compgen
ls xx使用正常,但是有特殊字符或空格的的文件没有转义了,能不能用'括起来
cd +tab 系统补全
cd xx +tab 没有补全

在wsl中改了还是闪退

大概是因为 debian 或 msys2 中没有装 bash-completion
请尝试先执行

sudo apt install bash-completion

或其他办法安装 bash-completion

相关代码
https://github.com/AOSC-Dev/bash-pinyin-completion-rs/blob/main/scripts/bash_pinyin_completion#L6-L10

如果仍然存在问题,请先执行 set -x 后使用补全,将输出的调试讯息给出,以便开发者分析,谢谢!

msys

>Chen@ pinyin_test$ ls
 bash_pinyin_completion*          normal_file.txt  '有 空格.txt'
 bash_pinyin_completion.rename*   normal_folder/    测试文件夹/
'dir with space'/                'with space.txt'  '特殊 字符目录'/
 issue.md                         中文名称.txt

>Chen@ pinyin_test$ ls 中文名称.txt
中文名称.txt

>Chen@ pinyin_test$ ls 有 空格.txt
ls: cannot access '': No such file or directory
ls: cannot access '空格.txt': No such file or directory

>Chen@ pinyin_test$ ls ceui
ls: cannot access 'ceui': No such file or directory

>Chen@ pinyin_test$ ls 测试文件夹

>Chen@ pinyin_test$ ls 特殊 字符目录
ls: cannot access '特殊': No such file or directory
ls: cannot access '字符目录': No such file or directory

>Chen@ pinyin_test$ cd
dir with space/ normal_folder/  测试文件夹/     特殊 字符目录/

>Chen@ pinyin_test$ cd ^C

>Chen@ pinyin_test$ cd teuu^C

>Chen@ pinyin_test$ cd ceui^C

>Chen@ pinyin_test$ set -x
++ history -a

>Chen@ pinyin_test$ cd teuu+ local cur prev words cword comp_args
+ _comp_initialize -- cd teuu cd
+ local exclude= opt_split= outx= errx= inx=
+ local flag OPTIND=1 OPTARG= OPTERR=0
+ getopts n:e:o:i:s flag -- cd teuu cd
+ shift 1
+ (( 3 ))
+ comp_args=("$@")
+ COMPREPLY=()
+ local 'redir=@(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-
<]))|&>?(>))'
+ _comp_get_words -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
+ (( OPTIND += 1 ))
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ (( OPTIND += 1 ))
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ (( OPTIND += 1 ))
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ (( OPTIND += 1 ))
+ [[ 6 -ge 7 ]]
+ _comp__get_cword_at_cursor '<>&' words cword cur
+ words=()
+ local cword words
+ _comp__reassemble_words '<>&' words cword
+ local exclude= i j line ref
+ [[ -n <>& ]]
+ exclude='[<>&]'
+ printf -v cword %s 1
+ [[ -n [<>&] ]]
+ line='cd teuu'
+ (( i = 0, j = 0 ))
+ (( i < 2 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ printf -v 'words[0]' %s cd
+ line=' teuu'
+ (( i == COMP_CWORD ))
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 1 -gt 0 ]]
+ [[ teuu == +([<>&]) ]]
+ ref='words[1]'
+ printf -v 'words[1]' %s teuu
+ line=
+ (( i == COMP_CWORD ))
+ printf -v cword %s 1
+ (( i++, j++ ))
+ (( i < 2 ))
+ (( i == COMP_CWORD ))
+ local i cur= index=7 'lead=cd teuu'
+ [[ 7 -gt 0 ]]
+ [[ -n cd teuu ]]
+ [[ -n cdteuu ]]
+ cur='cd teuu'
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 7 -ge 2 ]]
+ [[ cd != \c\d ]]
+ (( i < cword ))
+ local old_size=7
+ cur=' teuu'
+ local new_size=5
+ (( index -= old_size - new_size ))
+ (( ++i ))
+ (( i <= cword ))
+ [[ 5 -ge 4 ]]
+ [[  teu != \t\e\u\u ]]
+ cur=teuu
+ (( index > 0 ))
+ (( index-- ))
+ [[ 4 -ge 4 ]]
+ [[ teuu != \t\e\u\u ]]
+ (( i < cword ))
+ (( ++i ))
+ (( i <= cword ))
+ [[ -n teuu ]]
+ [[ ! -n teuu ]]
+ (( index < 0 ))
+ local 'IFS=
'
+ local words cword cur
+ _comp_upvars -a2 words cd teuu -v cword 1 -v cur teuu
+ (( 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=teuu
+ shift 3
+ (( 0 ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v "$vcur" "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v "$vcword" "$cword")
+ [[ -n prev ]]
+ local value=
+ (( cword >= 1 ))
+ value=cd
+ upvars+=("$vprev")
+ upargs+=(-v "$vprev" "$value")
+ [[ -n words ]]
+ local 'IFS=
'
+ upvars+=("$vwords")
+ upargs+=(-a"${#words[@]}" "$vwords" ${words+"${words[@]}"})
+ (( 4 ))
+ local cur cword prev words
+ _comp_upvars -v cur teuu -v cword 1 -v prev cd -a2 words cd teuu
+ (( 13 ))
+ (( 13 ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=teuu
+ 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=cd
+ 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 ))
+ _comp_compgen_variables
+ [[ teuu =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]
+ [[ teuu =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
+ [[ teuu =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*]$ ]]
+ return 1
+ [[ teuu == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-<]
))|&>?(>))* ]]
+ [[ cd == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-<]))
|&>?(>)) ]]
+ local i skip
+ (( i = 1 ))
+ (( i < 2 ))
+ [[ teuu == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|<?([>&])|<<?([-<]
))|&>?(>))* ]]
+ (( i++ ))
+ (( 1 ))
+ (( i < 2 ))
+ (( cword <= 0 ))
+ prev=cd
+ [[ -n '' ]]
+ return 0
+ [[ teuu == -* ]]
+ local i j k
+ compopt -o filenames
+ [[ ! -n '' ]]
+ _comp_compgen_filedir -d
+ _comp_compgen_tilde
+ [[ teuu == \~* ]]
+ return 1
+ local -a toks
+ local _arg=-d
+ [[ -d == -d ]]
+ _comp_compgen -v toks -- -d
+ __bak_comp_compgen -v toks -- -d
+ local _append=
+ local _var=
+ local _cur=teuu
+ local _dir=
+ local '_ifs=
' _has_ifs=
+ local _icmd= _xcmd=
+ _upvars=()
+ local -a _upvars
+ local _old_nocasematch=
+ shopt -q nocasematch
+ local OPTIND=1 OPTARG= OPTERR=0 _opt
+ getopts :av:U:Rc:C:lF:i:x: _opt -v toks -- -d
+ case $_opt in
+ [[ toks == @(*[^_a-zA-Z0-9]*|[0-9]*||_*|IFS|OPTIND|OPTARG|OPTERR|cur) ]]
+ _var=toks
+ getopts :av:U:Rc:C:lF:i:x: _opt -v toks -- -d
+ [[ -n '' ]]
+ shift 3
+ (( 1 == 0 ))
+ [[ ! -n toks ]]
+ [[ -d != -* ]]
+ [[ -n '' ]]
+ [[ -n '' ]]
+ local 'IFS=
'
+ [[ -d == *\$[0-9]* ]]
+ [[ -d == *\$\{[0-9]* ]]
+ local _result
++ [[ -n '' ]]
++ IFS='
'
++ compgen -d -- teuu
+ _result=
+ _comp_compgen__error_fallback
+ local _status=1
+ [[ -n '' ]]
+ eval -- 'toks=()'
++ toks=()
+ return 1
+ return
+ local original_result=1
+ local is_file_completion=false
+ compgen_args=('-v' 'toks' '--' '-d')
+ local compgen_args
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ is_file_completion=true
+ break
+ [[ true == true ]]
+ _add_completion -v toks -- -d
+ local cur
+ eval cur=
++ cur=
+ [[ -z '' ]]
+ return
+ return 1
+ (( 0 != 0 ))
+ local 'IFS=
'
+ _comp_compgen -U toks set
+ __bak_comp_compgen -U toks set
+ local _append=
+ local _var=
+ local _cur=teuu
+ local _dir=
+ local '_ifs=
' _has_ifs=
+ local _icmd= _xcmd=
+ _upvars=()
+ local -a _upvars
+ local _old_nocasematch=
+ shopt -q nocasematch
+ local OPTIND=1 OPTARG= OPTERR=0 _opt
+ getopts :av:U:Rc:C:lF:i:x: _opt -U toks set
+ case $_opt in
+ [[ toks == @(*[^_a-zA-Z0-9]*|[0-9]*|) ]]
+ [[ toks == @(_*|IFS|OPTIND|OPTARG|OPTERR|cur) ]]
+ _upvars+=("$OPTARG")
+ getopts :av:U:Rc:C:lF:i:x: _opt -U toks set
+ _comp_unlocal toks
+ (( BASH_VERSINFO[0] >= 5 ))
+ shopt -q localvar_unset
+ unset -v toks
+ [[ -n '' ]]
+ local _comp_compgen__append=
+ local _comp_compgen__var=COMPREPLY
+ local _comp_compgen__cur=teuu cur=teuu
+ _comp_compgen_set
+ local _append=
+ local _var=COMPREPLY
+ eval -- 'COMPREPLY=("$@")'
++ COMPREPLY=("$@")
+ (( 0 ))
+ local _status=1
+ [[ -n '' ]]
+ return 1
+ local original_result=1
+ local is_file_completion=false
+ compgen_args=('-U' 'toks' 'set')
+ local compgen_args
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ for arg in "${compgen_args[@]}"
+ case "$arg" in
+ [[ false == true ]]
+ return 1
+ return
>Chen@ pinyin_test$ cd teuu
2025-09-01-20-52-07.msys.mp4

bash-completion 你用的是哪个版本

wsl(debian)

chen@ ~$ uname -a
Linux Laptop 5.15.146.1-microsoft-standard-WSL2 #3 SMP Fri Apr 12 23:42:18 CST 2024 x86_64 GNU/Linux

chen@ ~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

chen@ ~$ apt show bash-completion
Package: bash-completion
Version: 1:2.11-2
Priority: standard
Section: shells
Maintainer: Gabriel F. T. Gomes <gabriel@debian.org>
Installed-Size: 1,560 kB
Provides: dh-sequence-bash-completion
Homepage: https://github.com/scop/bash-completion
Tag: implemented-in::shell, interface::shell, role::plugin, role::program
Download-Size: 234 kB
APT-Manual-Installed: yes
APT-Sources: https://mirrors.tuna.tsinghua.edu.cn/debian bullseye/main amd64 Packages
Description: programmable completion for the bash shell
 bash completion extends bash's standard completion behavior to achieve
 complex command lines with just a few keystrokes.  This project was
 conceived to produce programmable completion routines for the most
 common Linux/UNIX commands, reducing the amount of typing sysadmins
 and programmers need to do on a daily basis.


chen@ ~$ . /etc/bash_completion

chen@ ~$ . bash_pinyin_completion
No function _comp_compgen__call_builtin found. Please install bash-completion first.

chen@ ~$ . bash_pinyin_completion.rename
No function _comp_compgen found. Please install bash-completion first.

的确 AOSC OS 以及我开发使用的bash-completion 版本是更新的。
函数 Hook 点不应该更改为 _comp_compgen,更新 bash- completion 应该可以解决这个问题。

将bash-copletion升级到2.16后并禁用zoxide正常使用了
zoxide的hook函数将cd占用了
改成eval "$(zoxide init bash --cmd j --hook pwd)"