From 5599b21c5fa6ceffa1be24b2974a4d402d06bf7a Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Thu, 3 Feb 2022 23:16:30 +0100 Subject: bash-completion: Use the correct index range when looking for the command word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $words[0] contains the first word on the command-line, the name of the program: apt. Also, the last word already typed on the command-line might be the command, don’t ignore it. --- completions/bash/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/bash/apt b/completions/bash/apt index 35716e7a7..94ad974b1 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -52,7 +52,7 @@ _apt() "policy") local command i - for (( i=0; i < ${#words[@]}-1; i++ )); do + for (( i=1; i < ${#words[@]}; i++ )); do if [[ " ${COMMANDS[*]} " == *" ${words[i]} "* ]]; then command=${words[i]} break -- cgit v1.2.3-70-g09d2 From 19ffda1489858d132551a267fccdf7ab03b5e103 Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Thu, 3 Feb 2022 23:23:27 +0100 Subject: Don’t bash-complete package names before the command word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, package names would get suggested at the cursor position `_` for a command line like this: ``` ~# apt _ install git vim ``` --- completions/bash/apt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/completions/bash/apt b/completions/bash/apt index 94ad974b1..f60f9e97c 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -67,8 +67,9 @@ _apt() ;; esac - # supported options per command - if [[ "$cur" == -* ]]; then + # When the cursor (cword) is before the command word (i), only suggest + # options but not package or file names: + if [[ $cur == -* || ( -v command && $cword -le $i ) ]]; then case ${command-} in install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove) COMPREPLY=( $( compgen -W '--show-progress @@ -167,6 +168,8 @@ _apt() return 0 ;; esac + + return fi # specific command arguments -- cgit v1.2.3-70-g09d2