Bash completion: apt install ./file.deb does not complete local .deb files

Offen Anfängerfreundlich
#153 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
85/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
bash, linux
Bereich
cli

Rechercherichtung

Das Issue nennt /etc/bash_completion.d/apt-linux-mint und den Fall des Paketnamens _apt als Einstiegspunkt. Lies diesen Fall und vergleiche seine Behandlung mit der apt-Vervollständigung von Debian; das Issue enthält eine getestete Bedingung und das erwartete Verhalten. Fertig ist die Arbeit, wenn lokale .deb-Pfade für apt install vervollständigt werden und die Vervollständigung von Paketnamen weiterhin funktioniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Problem

Tab completion does not work for local .deb files with apt install:

$ ls
slack-desktop-4.53.287-amd64.deb
$ sudo apt install ./slack<Tab>

Nothing completes. The same thing happens without sudo.

Cause

/etc/bash_completion.d/apt-linux-mint defines its own _apt function, which replaces the one from Debian's /usr/share/bash-completion/completions/apt. In Mint's version, install is grouped with the commands that take a package name, so the current word is always passed to apt-cache --no-generate pkgnames and never to file completion.

Debian's completion switches to .deb file completion when the word starts with ., /, or ~. That was added for Ubuntu in LP #1645815 (apt 1.4~beta2). Mint's script was written before apt install ./file.deb was supported and never picked up that change.

Environment

  • Linux Mint 22.3 (Zena)
  • mintsystem 8.6.5 (the installed apt-linux-mint is identical to master)
  • apt 2.8.4ubuntu0.1
  • bash-completion 1:2.11-8

Suggested fix

Add the same check Debian uses at the start of the package-name case:

     "build"|"build-dep"|"changelog"|"depends"|"download"|"install"|"list"|\
     "policy"|"recommends"|"rdepends"|"show"|"source")
+        if [[ "$opt" == "install" && ( "$cur" == .* || "$cur" == /* || "$cur" == ~* ) ]]; then
+            _filedir '?(u)deb'
+            return 0
+        fi
         COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
         2> /dev/null ) )
         return 0
         ;;

I tested this locally. apt install ./slack<Tab> completes to ./slack-desktop-4.53.287-amd64.deb, and apt install slac<Tab> still completes package names.

Longer-term idea

A more durable option would be for this script to handle only the Mint-specific commands (deb, add-repository, held, contains, and so on) and fall back to Debian's _apt for the standard subcommands. Then Mint would get upstream completion fixes automatically, which would also address the drift reported in #73. Rewriting the script would also be a chance to drop the deprecated have call reported in #138.

Vorherrschende Sprache
Python
Sterne
58
Forks
43
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus linuxmint/mintsystem

Alle Issues in linuxmint/mintsystem

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.