[tex-k] [feature] Can kpathsea have a shell completion?

Norbert Preining norbert at preining.info
Fri Jan 20 03:46:44 CET 2023


> if users `kpsewhich --print-completion XXsh` in their bashrc/zshrc, they can:

Here is a simple bash completion for kpsewhich:

*********** save as kpsewhich.bash into a completion.d dir ***
# kpsewhich completion                                     -*- shell-script -*-

# This bash completions script was generated by
# completely (https://github.com/dannyben/completely)
# Modifying it manually is not recommended

_kpsewhich_completions_filter() {
  local words="$1"
  local cur=${COMP_WORDS[COMP_CWORD]}
  local result=()

  if [[ "${cur:0:1}" == "-" ]]; then
    echo "$words"
  
  else
    for word in $words; do
      [[ "${word:0:1}" != "-" ]] && result+=("$word")
    done

    echo "${result[*]}"

  fi
}

_kpsewhich_completions() {
  local cur=${COMP_WORDS[COMP_CWORD]}
  local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
  local compline="${compwords[*]}"

  case "$compline" in
    *)
      while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_kpsewhich_completions_filter "-all -no-casefold-search -casefold-search -cnf-line= -debug= -D= -dpi= -engine= -expand-braces= -expand-path= -expand-var= -format= -help -help-formats -interactive -no-mktex= -mktex= -mode= -must-exist -path= -progname= -safe-in-name= -safe-out-name= -show-path= -subdir= -var-brace-value= -var-value= -version")" -- "$cur" )
      ;;

  esac
} &&
complete -F _kpsewhich_completions kpsewhich

# ex: filetype=sh
***********************************

Best

Norbert

--
PREINING Norbert                              https://www.preining.info
Mercari Inc.     +     IFMGA Guide     +     TU Wien     +     TeX Live
GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13


More information about the tex-k mailing list.