Skip to content

Commit

Permalink
bash-completion: fix local completion (RhBug:1151231)
Browse files Browse the repository at this point in the history
we will use dnf python api

Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1151231
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
  • Loading branch information
ignatenkobrain authored and Jan Silhan committed Dec 8, 2014
1 parent 133485e commit b7fa160
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions etc/bash_completion.d/dnf-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,50 @@ _dnf()
if [ -r $cache_file ]; then
COMPREPLY=( $( compgen -W '$( sqlite3 $cache_file "select pkg from available WHERE pkg LIKE \"$cur%\"" )' ) )
else
COMPREPLY=( $( compgen -W '$( dnf --cacheonly list $cur* 2>/dev/null | cut -d' ' -f1 )' -- "$cur" ) )
COMPREPLY=( $( compgen -W '$( python << END
import dnf
import os
import logging
class NullHandler(logging.Handler):
def emit(self, record):
pass
h = NullHandler()
logging.getLogger("dnf").addHandler(h)
b = dnf.Base()
b.read_all_repos()
if not dnf.util.am_i_root():
cachedir = dnf.yum.misc.getCacheDir()
b.conf.cachedir = cachedir
b.conf.substitutions["releasever"] = dnf.rpm.detect_releasever("/")
suffix = dnf.conf.parser.substitute(dnf.const.CACHEDIR_SUFFIX, b.conf.substitutions)
for repo in b.repos.values():
repo.basecachedir = os.path.join(b.conf.cachedir, suffix)
repo.md_only_cached = True
try:
b.fill_sack()
except dnf.exceptions.RepoError:
pass
q = b.sack.query().available()
for pkg in q:
print("{}.{}").format(pkg.name, pkg.arch)
END
)' -- "$cur" ) )
fi
[[ $command != "info" ]] && ext='@(rpm)' || ext=''
;;
remove|erase)
if [ -r $cache_file ]; then
COMPREPLY=( $( compgen -W '$( sqlite3 $cache_file "select pkg from installed WHERE pkg LIKE \"$cur%\"" )' ) )
else
COMPREPLY=( $( compgen -W '$( rpm -qav --qf "%{NAME}.%{ARCH}\n" | grep -E "^$cur" )' -- "$cur" ) )
COMPREPLY=( $( compgen -W '$( python << END
import hawkey
sack = hawkey.Sack()
sack.load_system_repo()
q = hawkey.Query(sack).filter(reponame=hawkey.SYSTEM_REPO_NAME)
for pkg in q:
print("{}.{}").format(pkg.name, pkg.arch)
END
)' -- "$cur" ) )
fi
ext=''
;;
Expand Down

0 comments on commit b7fa160

Please sign in to comment.