#!/usr/bin/env bash # # Sym command line completion # # © 2015-2016, Konstantin Gredeskoul, https://github.com/kigster/sym # MIT LICENSE # _sym() { local SYM_OPTS SYM_POINTS cur prev cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" COMPREPLY=() #[[ $COMP_CWORD == 1 ]] && SYM_COMP_OPTIONS="${SYM_COMP_OPTIONS} ${SYM_COMMANDS}" if [[ $prev =~ "-f" || $prev =~ "-o" || $prev =~ "-K" || $prev == "--keyfile" ]] ; then SYM_COMP_OPTIONS="$(find . -type f -depth 1 | sed 's#^.\/##g')" elif [[ "${cur}" == '-' || "${cur}" == -* ]] ; then export DICT_SYM_COMP_OPTIONS=${DICT_SYM_COMP_OPTIONS:-$(sym --dictionary | sed -E 's/ /\n/g')} SYM_COMP_OPTIONS=${DICT_SYM_COMP_OPTIONS} else SYM_COMP_OPTIONS="$(find . -type f -depth 1 -name "${prev}*" | sed 's#^.\/##g')" fi COMPREPLY=( $(compgen -W "${SYM_COMP_OPTIONS}" -- ${cur}) ) return 0 } complete -F _sym sym