Skip to content

Commit

Permalink
origin/main feat(contrib/completions): Add initial bash shell complet…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
etu committed Jun 15, 2024
1 parent 998dd7f commit eb2e3c6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions contrib/completions/goprocmgr.bash
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

0 comments on commit eb2e3c6

Please sign in to comment.