Created
December 4, 2019 12:16
-
-
Save sergio-correia/79457e1b8e6db2cf9c5dc78bdf79e400 to your computer and use it in GitHub Desktop.
clevis bash completion - experimental
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash completion support for clevis. | |
_clevis() { | |
local dir prev cur field | |
dir=$(dirname "$(command -v clevis)") | |
prev=${COMP_WORDS[COMP_CWORD-1]} | |
cur=${COMP_WORDS[COMP_CWORD]} | |
field=$((COMP_CWORD + 1)) | |
if [ "${prev}" = '-d' ]; then | |
cur=${cur:=/dev/} | |
_filedir | |
return | |
fi | |
if [[ ${COMP_WORDS[COMP_CWORD-1]} == "clevis" ]]; then | |
name="clevis-*" | |
fi | |
if [[ ${COMP_WORDS[COMP_CWORD-2]} == "clevis" ]]; then | |
name="clevis-${COMP_WORDS[COMP_CWORD-1]}-*" | |
fi | |
suggestions=$(find "${dir}" -name "${name}" -executable \ | |
| cut -d '-' -f"${field}" | sort | uniq) | |
if [[ -n "${cur}" ]]; then | |
suggestions=$(for word in "${suggestions[@]}"; do \ | |
echo "${word}" | grep -- "${cur}"; done) | |
fi | |
COMPREPLY=($(compgen -W "${suggestions}" -- "${cur}")) | |
} | |
complete -F _clevis clevis | |
# vim: set ts=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment