Hello! This is my first time with zsh development, so I hope I will not miss anything. I am using zsh 5.8 shipped with Gentoo, no patches. I use oh-my-zsh with plugins=(tig gitfast colored-man-pages colorize command-not-found cp dirhistory autojump sudo fast-syntax-highlighting zsh-autosuggestions) and ZSH_THEME="powerlevel10k/powerlevel10k" and no further customisations, but I hope this is irrelevant, just activates the completion functions. The bug is not critical in any way, but just happens in the following setting: zsh-5.8% gdb (cursor here) -h Then it is enough to hit Tab. The -h can be any other option, or even a file name, not really important, but there has to be space before cursor, and after it (I guess so). This is the error message: _pids:shift:13: shift count must be <= $# _pids:compadd:42: bad option: -m I traced it down to most probably /usr/share/zsh/5.8/functions/Completion/Unix/_gdb calling _pids, but I do not know enough of zsh completion to investigate more. Glad to have found a bug in such reliable software! Arusekk
Arusekk wrote on Sun, Nov 22, 2020 at 23:39:53 +0100: > _pids:shift:13: shift count must be <= $# > _pids:compadd:42: bad option: -m I can reproduce this. > I traced it down to most probably > /usr/share/zsh/5.8/functions/Completion/Unix/_gdb calling _pids, but I do > not know enough of zsh completion to investigate more. fned it and add «typeset -p w >/dev/tty» right before the call and you'll see that w=('' -h) at that point; then, the parameter expansion in the call to _pids isn't quoted and expands to an empty string, hence it's elided, causing the error. Unsure of the fix. Cheers, Daniel > Glad to have found a bug in such reliable software! > Arusekk > >
On 22 Nov, Arusekk wrote: > The bug is not critical in any way, but just happens in the following > setting: > > zsh-5.8% gdb (cursor here) -h > _pids:shift:13: shift count must be <= $# > _pids:compadd:42: bad option: -m In this case, I think we can fix this by limiting the search of the $words array to words preceding the cursor as in the following patch. I've also updated somewhat the pattern for options that might take an argument in a following word. In general, gdb completion could be improved quite a bit more. > Glad to have found a bug in such reliable software! > Arusekk Thanks for reporting this and sorry for not dealing with it sooner. Oliver diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb index 18f797633..6bdd55946 100644 --- a/Completion/Unix/Command/_gdb +++ b/Completion/Unix/Command/_gdb @@ -40,9 +40,9 @@ else (-b) _baudrates && return 0 ;; esac - w=( "${(@)words[2,-1]}" ) + w=( "${(@)words[2,CURRENT-1]}" ) while [[ "$w[1]" = -* ]]; do - [[ "$w[1]" = -[decsxb] ]] && shift 1 w + [[ "$w[1]" = -(cd|se|tty|[decsxb]) ]] && shift 1 w shift 1 w done