# bash completion for mkhint # Install: sudo cp mkhint.bash-completion /etc/bash-completion.d/mkhint _mkhintfile_completions() { local cur prev repo_dir hint_dir mkhint_config _init_completion || return repo_dir="/var/lib/sbopkg/SBo-danix" hint_dir="/etc/slackrepo/SBo-danix/hintfiles" mkhint_config="$HOME/.config/mkhint/config" # shellcheck disable=SC1090 [[ -f "$mkhint_config" ]] && source "$mkhint_config" repo_dir="${REPO_DIR:-$repo_dir}" hint_dir="${HINT_DIR:-$hint_dir}" repo_dir="${repo_dir%/}"; hint_dir="${hint_dir%/}" local all_flags="--version -v --set-version -V --hintfile -f --new -n --list -l --review -R --clean -c --check -C --fix-current -F --delete -d --no-dl -N --info -i --force --help -h" # -R/--review and -l/--list take any number of hint names; complete them repeatedly. local w in_review="" for w in "${COMP_WORDS[@]:1}"; do [[ "$w" == "-R" || "$w" == "--review" || "$w" == "-l" || "$w" == "--list" ]] && in_review=1 done if [[ -n "$in_review" && "$cur" != -* ]]; then local -a rwords=() for f in "$hint_dir"/*.hint; do [[ -f "$f" ]] && rwords+=("$(basename "${f%.hint}")") done COMPREPLY=($(compgen -W "${rwords[*]}" -- "$cur")) return fi case "$prev" in --new|-n|--info|-i) # Packages live at REPO_DIR///; complete the pkg dir # names. Strip the trailing slash and category prefix with param # expansion (no per-dir basename fork — the repo has thousands). local -a words=() d for d in "$repo_dir"/*/*/; do d="${d%/}"; words+=("${d##*/}") done COMPREPLY=($(compgen -W "${words[*]}" -- "$cur")) ;; --hintfile|-f|--delete|-d|--check|-C) local -a words=() for f in "$hint_dir"/*.hint; do [[ -f "$f" ]] && words+=("$(basename "${f%.hint}")") done COMPREPLY=($(compgen -W "${words[*]}" -- "$cur")) ;; --set-version|-V) # Suggest a version: with -f/--hintfile pull it from the # hint's VERSION; with -n/--new pull it from the SBo .info. local pkg="" src="" i for (( i=1; i<${#COMP_WORDS[@]}-1; i++ )); do case "${COMP_WORDS[i]}" in --hintfile|-f) pkg="${COMP_WORDS[i+1]}"; src=hint; break ;; --new|-n) pkg="${COMP_WORDS[i+1]}"; src=info; break ;; esac done if [[ -n "$pkg" ]]; then local ver="" f if [[ "$src" == hint ]]; then f="$hint_dir/${pkg}.hint" else # .info lives at REPO_DIR///.info for f in "$repo_dir"/*/"$pkg"/"$pkg".info; do [[ -f "$f" ]] && break done fi if [[ -f "$f" ]]; then ver=$(grep -m1 '^VERSION=' "$f" | cut -d= -f2 | tr -d '"') [[ -n "$ver" ]] && COMPREPLY=($(compgen -W "$ver" -- "$cur")) fi fi ;; *) COMPREPLY=($(compgen -W "$all_flags" -- "$cur")) ;; esac } complete -F _mkhintfile_completions mkhint.sh mkhint