#/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 if [[ -e ./km-package-install ]]; then python3 -c "from imp import load_source;load_source('km_package_install', './km-package-install');from km_package_install import list_keyboards;list_keyboards()" else python3 -c "from imp import load_source;load_source('km_package_install', '/usr/bin/km-package-install');from km_package_install import list_keyboards;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