spiegel-keyman/linux/keyman-config/km-package-install.bash-completion
Eberhard Beilharz 3eb4b58a58
fix(linux): Remove tab completion warning
This is done by replacing the deprecated `imp` module.

Fixes #6227.
2022-04-11 16:30:22 +02:00

49 lines
2 KiB
Text

#/usr/bin/env bash
_km-package-install_completions()
{
local cur prev opts cache
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-h --help -v --verbose -vv --veryverbose --version -p --package -f --file -s --shared"
cache=${XDG_CACHE_HOME:-~/.cache}/keyman/kmpdirlist
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
case "${prev}" in
"-p"|"--package")
words=""
if [[ ! -s $cache ]] ; then
# NOTE: identical code in `km-package-get.bash-completion`.
# Unfortunately with bash completion scripts it's not possible to factor out
# common code.
if [[ -e ./km-package-install ]]; then
python3 -c "from importlib.machinery import SourceFileLoader;from importlib.util import module_from_spec, spec_from_loader;loader = SourceFileLoader('km_package_install', './km-package-install');spec = spec_from_loader(loader.name, loader);mod = module_from_spec(spec);loader.exec_module(mod);mod.list_keyboards()"
else
python3 -c "from importlib.machinery import SourceFileLoader;from importlib.util import module_from_spec, spec_from_loader;loader = SourceFileLoader('km_package_install', '/usr/bin/km-package-install');spec = spec_from_loader(loader.name, loader);mod = module_from_spec(spec);loader.exec_module(mod);mod.list_keyboards()"
fi
fi
if [[ -r $cache ]] ; then
for file in `cat $cache`; do words="${words} ${file}"; done
COMPREPLY=($(compgen -W "${words}" -- ${cur}))
return 0
fi
;;
"-f"|"--file")
local IFS=$'\n'
compopt -o filenames
COMPREPLY=( $(compgen -f -X "!"*.kmp -- $cur) $(compgen -d -- $cur) )
return 0
;;
*)
;;
esac
}
complete -F _km-package-install_completions km-package-install