Last active
August 14, 2021 14:56
-
-
Save ramn/741f13997c9cd90a4fa6 to your computer and use it in GitHub Desktop.
Bash command completion builder
This file contains hidden or 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
#!/bin/bash | |
# | |
# Build shell command completions | |
# | |
function _build_completions { | |
local current_word | |
COMPREPLY=() | |
current_word=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=($(compgen -W "$($1)" -- $current_word)) | |
} | |
function _build_completions_for_first_script { | |
# './first_script display_all_my_commands' outputs all commands | |
# that can be completed for ./first_script, as a space delimited list. | |
_build_completions './first_script display_all_my_commands' | |
} | |
function _build_completions_for_second_script { | |
_build_completions './second_script display_all_my_commands' | |
} | |
complete -o nospace -F _build_completions_for_first_script './first_script' | |
complete -o nospace -F _build_completions_for_second_script './second_script' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment