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

オープン 初心者向け
#153 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bash, linux
領域
cli

調査の方向性

issue では、/etc/bash_completion.d/apt-linux-mint とパッケージ名 _apt のケースを調査の出発点として示しています。そのケースを読み、Debian の apt 補完での処理と比較してください。issue にはテスト済みの条件と期待される動作が記載されています。apt install でローカルの .deb パスが補完され、パッケージ名の補完も引き続き機能すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
58
フォーク
43
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

linuxmint/mintsystem のほかの issue

linuxmint/mintsystem の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。