#!/bin/bash # dpkg-query(1) bash completion # # Copyright © 2002 Laurent Martelli # Copyright © 2002 Chris Lawrence # Copyright © 2002-2004 Ian Macdonald # Copyright © 2002 Rafael Sepúlveda # Copyright © 2002 Guillaume Rousse # Copyright © 2004 Philipp Weis # Copyright © 2004 Itay Ben-Yaacov # Copyright © 2008-2011 David Paleino # Copyright © 2009-2026 Ville Skyttä # Copyright © 2013 Igor Murzov # Copyright © 2015 Andrea Dari # Copyright © 2018 Uwe Storbeck # Copyright © 2018 Luca Capello # Copyright © 2018 Gabriel F. T. Gomes # Copyright © 2021-2023 Koichi Murase # Copyright © 2024 Arnaud Rebillout # Copyright © 2026 Guillem Jover # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . _comp_cmd_dpkg_compgen__control_files() { local pkg pkg="${words[$((cword - 1))]}" _comp_compgen_split -- "$(command dpkg-query --control-list "$pkg")" } # dpkg-query(1) completion # _comp_cmd_dpkg_query() { # shellcheck disable=SC2034 local cur prev words cword was_split comp_args _comp_initialize -s -- "$@" || return local args i=$cword # Find the last option flag. if [[ $cur != -* ]]; then while [[ $prev != -* && $i -ne 1 ]]; do prev=${words[--i - 1]} done fi local noargopts='!(-*|*[splLWSc]*)' # shellcheck disable=SC2254 case $prev in --status | \ --print-avail | \ --list | \ --show | \ --control-list | \ -${noargopts}[splW]) _comp_compgen -x dpkg installed_packages return ;; --control-show | \ --control-path) # Find how many real args used so far. for ((i = 1; i < cword; i++)); do if [[ ${words[i]} == --@(control-show|control-path) ]]; then args=$((cword - i)) break fi done case $args in 1) _comp_compgen -x dpkg installed_packages return ;; 2) _comp_cmd_dpkg_compgen__control_files return ;; esac return ;; --listfiles | \ -${noargopts}[L]) _comp_compgen -x dpkg purgeable_packages return ;; --search | \ -${noargopts}S) _comp_compgen_filedir return ;; --admindir | \ --root) _comp_compgen_filedir -d return ;; esac [[ $was_split ]] && return _comp_compgen_help [[ ${COMPREPLY-} == *= ]] && compopt -o nospace } && complete -F _comp_cmd_dpkg_query dpkg-query