Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash-completion: use sqlite cache when available (BZ: 1815895) #1817

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion etc/bash_completion.d/dnf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ __dnf_repopkgs_subcmds="
upgrade upgrade-to
"

__dnf_cache_file="/var/cache/dnf/packages.db"

_dnf_query_db()
{
local table=$1
local prefix=$2
local query="select pkg from $table where pkg like \"$prefix%\""
if [ "$table" = "available" ]; then
# The available table contains both installed and non-installed
# packages. Exclude the installed packages.
query="$query and pkg not in (select pkg from installed)"
fi
sqlite3 -batch -init /dev/null "$__dnf_cache_file" "$query"
}

__dnf_python_exec=
_dnf_set_python_exec()
{
Expand Down Expand Up @@ -148,7 +163,23 @@ _dnf_show_packages()
shift

if ! _dnf_is_path "$cur"; then
COMPREPLY+=( $(compgen -W "$( _dnf_commands_helper $cmd "$@" "$cur" )") )
if [ -r "$__dnf_cache_file" ] && [ -x /usr/bin/sqlite3 ]; then
case "$cmd$*" in
listinstalled|listupdates|\
dg|downgrade|\
ri|rei|reinstall|\
rm|remove*|erase*|\
um|u-m|upgrade|upgrade-n*|\
up|up-min|update|update-n*)
COMPREPLY+=( $(_dnf_query_db installed "$cur") )
;;
*)
COMPREPLY+=( $(_dnf_query_db available "$cur") )
;;
esac
else
COMPREPLY+=( $(compgen -W "$( _dnf_commands_helper $cmd "$@" "$cur" )") )
fi
fi

[[ $COMPREPLY ]] && return
Expand Down