Skip to content

Commit

Permalink
Merge pull request #3 from biapy/bash_completion
Browse files Browse the repository at this point in the history
feat: ✨ add bash_completion configuration for bashembler
  • Loading branch information
landure authored Jul 4, 2023
2 parents 25a7d89 + 1b42c60 commit 7f4487e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions completion/bashembler
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @file completion/bashembler
# @author Pierre-Yves Landuré < contact at biapy dot fr >
# @brief bash-completion for bashembler.
# @description
# bash-completion configuration for bashembler command-line.

# @description
# Generate bash-completion for bashembler.
#
# @example
# complete -F '_bashembler' 'bashembler'
#
# @arg $1 string name of the command whose arguments are being completed (bashembler).
# @arg $2 string word being completed.
# @arg $3 string word preceding the word being completed
#
# @set COMPREPLY the bashembler completion list.
#
# @exitcode 0 If completion successfully generated.
# @exitcode 1 If the number of arguments is invalid.
# @exitcode 2 If the command name is invalid.
#
# @see https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
function _bashembler() {
[[ "${#}" -ne 3 ]] && return 1
[[ "${1}" != 'bashembler' ]] && return 2
# latest="${COMP_WORDS[${COMP_CWORD}]}"
local latest="${2}"

local words=(
'-h' '-?' '--help' '-V' '--version' '-q' '--quiet' '-v' '--verbose'
'-c' '--discard-comments' '-w' '--overwrite' '-o' '--output'
)

if [[ "${latest}" =~ ^--output= ]]; then
mapfile -t 'COMPREPLY' \
< <(compgen -P '--output=' -f -- "${latest##--output=}")
return 0
fi

local words_string
printf -v 'words_string' "%s" "${words[@]/#/ }"
mapfile -t 'COMPREPLY' \
< <(compgen -W "${words_string}" -f -- "${latest}")
return 0
}

complete -o 'filenames' -F '_bashembler' 'bashembler'

0 comments on commit 7f4487e

Please sign in to comment.