]> git.saurik.com Git - apt.git/commitdiff
bash-completion: Only complete understood file paths for install
authorJohn R. Lenton <jlenton@gmail.com>
Wed, 30 Nov 2016 09:28:27 +0000 (09:28 +0000)
committerJohn R. Lenton <jlenton@gmail.com>
Wed, 30 Nov 2016 11:15:08 +0000 (11:15 +0000)
Previouosly apt's bash completion was such that, given

    $ mkdir xyzzz
    $ touch xyzzy.deb xyzzx.two.deb

you'd get

    $ apt install xyzz<tab>
    xyzzx.two.deb  xyzzz/
    $ apt install /tmp/foo/xyzz<tab>
    xyzzx.two.deb  xyzzz/

this is inconsistent (xyzzx.two.deb is listed but not xyzzy.deb), but
worse than that it offered things that apt would not actually
recognise as candidates for install:

    $ sudo apt install xyzzx.two.deb
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package xyzzx.two.deb
    E: Couldn't find any package by glob 'xyzzx.two.deb'
    E: Couldn't find any package by regex 'xyzzx.two.deb'

With this small (trival, really) change, apt's bash completion will
only offer things apt understands, and won't recquire an aditional
period in the filename to offer it:

    $ apt install xyzz<tab>^C
    $ # (no completions!)
    $ apt install ./xyzz<tab>
    xyzzx.two.deb  xyzzy.deb      xyzzz/
    $ apt install /tmp/foo/xyzz
    xyzzx.two.deb  xyzzy.deb      xyzzz/

fixes #28

LP: #1645815

completions/bash/apt

index 451004982e03ec9605eb327a9f9c601a9faa735f..f7dd61f3b791d75ad862dcf579ea1e730b0a272c 100644 (file)
@@ -189,7 +189,9 @@ _apt()
             install)
                 COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                     2> /dev/null ) )
-                _filedir "*.deb"
+                if [[ "$cur" == ./* || "$cur" == /* ]]; then
+                    _filedir "deb"
+                fi
                 return 0
                 ;;
             source|build-dep|showsrc|policy)