-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from biapy/bash_completion
feat: ✨ add bash_completion configuration for bashembler
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
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' |