Last active
June 26, 2022 16:13
-
-
Save reporter123/4d80a2c2817f6c18f634edaeee28ee13 to your computer and use it in GitHub Desktop.
Partial bash completion for ng. This is a more functional version than the two liner in circulation.
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
_ng() { | |
local cur prev opts | |
local NG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n" | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts="--help" | |
posopts="${NG_COMMANDS}" | |
if [[ ${cur} != -* && ${COMP_CWORD} -eq 1 ]] ; then | |
COMPREPLY=( $(compgen -W "${posopts}" -- ${cur}) ) | |
return 0 | |
elif [[ ${cur} == -* ]] ; then | |
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | |
return 0 | |
fi | |
case "${prev}" in | |
"generate"|"g") | |
opts="--help -d -f --force --dry-run --defaults" | |
posopts="class component module service" | |
if [[ ${cur} != -* ]]; then | |
COMPREPLY=($(compgen -W "${posopts}" -- ${cur})) | |
else | |
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | |
fi | |
;; | |
"help") | |
opts="--help" | |
if [[ ${cur} == -* ]]; then | |
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | |
fi | |
;; | |
esac | |
} | |
command_exists () { | |
command -v $1 >/dev/null 2>&1; | |
} | |
if command_exists ng; then | |
# No longer supported, please see https://github.com/angular/angular-cli/issues/11043 | |
# . <(ng completion --bash) | |
complete -F _ng ng | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Google now seems to have resurrected the official in Angular support. Consider this file obsolete. Largely here as a reference for how this can be done in the absence of official support.