File: km-package-get.bash-completion

package info (click to toggle)
keyman 18.0.245-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,316 kB
  • sloc: python: 52,784; cpp: 21,278; sh: 7,633; ansic: 4,823; xml: 3,617; perl: 959; makefile: 139; javascript: 138
file content (40 lines) | stat: -rw-r--r-- 1,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# shellcheck disable=SC2148
# No hashbang for bash completion scripts! They are intended to be sourced, not executed.

_km-package-get_completions()
{
    local cur opts cache pkg_install_path
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    opts="-h --help -v --verbose -vv --veryverbose --version"

    cache=${XDG_CACHE_HOME:-~/.cache}/keyman/kmpdirlist

    if [[ ${cur} == -* ]] ; then
        # shellcheck disable=SC2207
        COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
        return 0
    fi

    words=""
    if [[ ! -e $cache ]] ; then
        # NOTE: identical code in `km-package-install.bash-completion`.
        # Unfortunately with bash completion scripts it's not possible to factor out
        # common code.
        if [[ -e ./km-package-install ]]; then
            pkg_install_path='./km-package-install'
        else
            pkg_install_path='/usr/bin/km-package-install'
        fi
        python3 -c "from importlib.machinery import SourceFileLoader;from importlib.util import module_from_spec, spec_from_loader;loader = SourceFileLoader('km_package_install', $pkg_install_path);spec = spec_from_loader(loader.name, loader);mod = module_from_spec(spec);loader.exec_module(mod);mod.list_keyboards()"
    fi

    if [[ -r $cache ]] ; then
        while read -r file; do words="${words} ${file}"; done < "$cache"
        # shellcheck disable=SC2207
        COMPREPLY=($(compgen -W "${words}" -- "${cur}"))
        return 0
    fi
}

complete -F _km-package-get_completions km-package-get