Bug#1067201: apt: Improved bash-completion for 'apt edit-sources'
Package: apt
Version: 2.7.13
Severity: minor
Tags: patch
Attached are minor improvements to 'apt edit-sources' bash completion:
- Generate accurate '*.list' list of files, and omit '.list'
suffixes. (I _would_ also list '*.sources', but current 'apt
edit-sources' does not support this newer file format.)
- Quote filenames as needed
- Honor $APT_CONFIG by calling 'apt-config' instead of hardcoding
/etc/apt/sources.list.d. (For efficiency, this is only in the
'edit-sources' codepath.)
Quoting filenames seems like overkill, but _could_ matter for users
who maintain a separate non-default config under $HOME. (I do this in
order to make many additional 'deb-src' available, with corresponding
trusted keys, without encumbering the systemwide 'apt update'.)
Thanks,
Peter
--- a/completions/bash/apt
+++ b/completions/bash/apt
@@ -2,7 +2,6 @@
_apt()
{
- local sourcesdir="/etc/apt/sources.list.d"
local cur prev words cword
_init_completion || return
@@ -211,8 +210,13 @@
return 0
;;
edit-sources)
- COMPREPLY=( $( compgen -W '$( command ls $sourcesdir )' \
- -- "$cur" ) )
+ mapfile -t COMPREPLY < <(
+ eval $(apt-config shell root Dir etcapt Dir::Etc sourcesdir Dir::Etc::sourceparts)
+ [[ $etcapt == /* ]] || etcapt=$root/$etcapt
+ [[ $sourcesdir == /* ]] || sourcesdir=$etcapt/$sourcesdir
+ IFS='
+' compgen -W "$(shopt -s nullglob; basename -s.list "$sourcesdir"/*.list)" -- "$cur")
+ compopt -o filenames
return 0
;;
moo)
Reply to: