From 969349ce82ef6fbb1f65e875eeab84c403f23c88 Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Tue, 25 Jan 2022 15:53:21 +0100 Subject: Also bash-complete .deb filenames after `apt install` for paths starting with ~ At the time the bash-completion runs, the ~ (or even ~user) is not yet expanded to /home/user, so it did not match the existing comparison with `/*`. --- completions/bash/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/bash/apt b/completions/bash/apt index 7cf54df1f..0e5d6f808 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -191,7 +191,7 @@ _apt() install) COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ 2> /dev/null ) ) - if [[ "$cur" == ./* || "$cur" == /* ]]; then + if [[ "$cur" == ./* || "$cur" == /* || "$cur" == ~* ]]; then _filedir "deb" fi return 0 -- cgit v1.2.3-70-g09d2 From ca5557936211bd670a203e6e1f8d75fda2d61819 Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Tue, 25 Jan 2022 15:57:22 +0100 Subject: Bash-complete either package name or .deb filename for `apt install` Should provide a tiny speed-up when someone already started typing either one in the current argument. --- completions/bash/apt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/completions/bash/apt b/completions/bash/apt index 0e5d6f808..61101d839 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -189,10 +189,11 @@ _apt() return 0 ;; install) - COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ - 2> /dev/null ) ) if [[ "$cur" == ./* || "$cur" == /* || "$cur" == ~* ]]; then _filedir "deb" + else + COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ + 2> /dev/null ) ) fi return 0 ;; -- cgit v1.2.3-70-g09d2 From 0251ed0b4f01b2813c31af9e5cbfe57dad61340d Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Wed, 26 Jan 2022 21:29:04 +0100 Subject: Start bash-completing .deb file paths after the first . passed in an argument to `apt install` This will start by suggesting ./ and ../ which are both fine path segments for `apt install` to handle later. --- completions/bash/apt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/bash/apt b/completions/bash/apt index 61101d839..90b4ef20c 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -189,7 +189,7 @@ _apt() return 0 ;; install) - if [[ "$cur" == ./* || "$cur" == /* || "$cur" == ~* ]]; then + if [[ "$cur" == .* || "$cur" == /* || "$cur" == ~* ]]; then _filedir "deb" else COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \ -- cgit v1.2.3-70-g09d2 From 783138b5bbeb36f4de09ab77bbef7c6f7f7234c6 Mon Sep 17 00:00:00 2001 From: Jörn-Thorben Hinz <11910-jth@users.noreply.salsa.debian.org> Date: Tue, 1 Feb 2022 14:04:53 +0100 Subject: Don’t fail bash-completion for `apt` when the nounset option is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following a practice from upstream bash-completion. See for example https://github.com/scop/bash-completion/commit/b807460140aa6dda09eb2af2ecf3afa1971c84c4 --- completions/bash/apt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/completions/bash/apt b/completions/bash/apt index 90b4ef20c..3a6b0682f 100644 --- a/completions/bash/apt +++ b/completions/bash/apt @@ -69,7 +69,7 @@ _apt() # supported options per command if [[ "$cur" == -* ]]; then - case $command in + case ${command-} in install|remove|purge|upgrade|dist-upgrade|full-upgrade|autoremove) COMPREPLY=( $( compgen -W '--show-progress --fix-broken --purge --verbose-versions --auto-remove @@ -170,7 +170,7 @@ _apt() fi # specific command arguments - if [[ -n $command ]]; then + if [[ -v command ]]; then case $command in remove|purge|autoremove) if [[ -f /etc/debian_version ]]; then @@ -214,10 +214,8 @@ _apt() return 0 ;; esac - fi - - # no command yet, show what commands we have - if [ "$command" = "" ]; then + else + # no command yet, show what commands we have COMPREPLY=( $( compgen -W '${COMMANDS[@]}' -- "$cur" ) ) fi -- cgit v1.2.3-70-g09d2