-
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.
origin/main feat(contrib/completions): Add initial bash shell complet…
…ions
- Loading branch information
Showing
1 changed file
with
64 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,64 @@ | ||
#!/usr/bin/env bash | ||
|
||
###################################################################### | ||
# _ | ||
# | | __ _ ___ _ __ _ __ ___ ___ _ __ ___ __ _ _ __ | ||
# / __) / _` |/ _ \| '_ \| '__/ _ \ / __| '_ ` _ \ / _` | '__| | ||
# \__ \ | (_| | (_) | |_) | | | (_) | (__| | | | | | (_| | | | ||
# ( / \__, |\___/| .__/|_| \___/ \___|_| |_| |_|\__, |_| | ||
# |_| |___/ |_| |___/ | ||
# | ||
# [goprocmgr] This program is a configuration manager and process | ||
# runner for servers, it has an http API to manage and | ||
# retrieve the configuration. It also provides a CLI | ||
# client for interacting with the API. | ||
# | ||
# https://github.com/TaserudConsulting/goprocmgr | ||
###################################################################### | ||
|
||
_goprocmgr() { | ||
local cur prev opts | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
||
opts="-config -serve -list -list-format -add -remove -start -stop -logs -version" | ||
|
||
case "${prev}" in | ||
-list-format) | ||
COMPREPLY=( $(compgen -W "table csv" -- ${cur}) ) | ||
return 0 | ||
;; | ||
-remove) | ||
COMPREPLY=( $(compgen -W "$(__goprocmgr_get_names)" -- ${cur}) ) | ||
return 0 | ||
;; | ||
-start) | ||
COMPREPLY=( $(compgen -W "$(__goprocmgr_get_stopped_names)" -- ${cur}) ) | ||
return 0 | ||
;; | ||
-stop|-logs) | ||
COMPREPLY=( $(compgen -W "$(__goprocmgr_get_running_names)" -- ${cur}) ) | ||
return 0 | ||
;; | ||
esac | ||
|
||
if [[ ${cur} == -* ]] ; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
fi | ||
} | ||
|
||
__goprocmgr_get_names() { | ||
goprocmgr -list -list-format csv 2>/dev/null | tail -n +2 | cut -d ',' -f 1 | ||
} | ||
|
||
__goprocmgr_get_running_names() { | ||
goprocmgr -list -list-format csv 2>/dev/null | awk -F ',' '$2 == "true" {print $1}' | ||
} | ||
|
||
__goprocmgr_get_stopped_names() { | ||
goprocmgr -list -list-format csv 2>/dev/null | awk -F ',' '$2 == "false" {print $1}' | ||
} | ||
|
||
complete -F _goprocmgr goprocmgr |