-
Notifications
You must be signed in to change notification settings - Fork 5
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 #25 from hseg/bash-completion
bash completion
- Loading branch information
Showing
1 changed file
with
66 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,66 @@ | ||
#!/bin/bash | ||
_server() { | ||
local cur prev | ||
|
||
prev=${COMP_WORDS[COMP_CWORD - 1]} | ||
cur=${COMP_WORDS[COMP_CWORD]} | ||
case "$prev" in | ||
-c) _filedir;; | ||
*) mapfile -t COMPREPLY < \ | ||
<(compgen -W '-c -d -v -vv -vvv -vvvv' -- "$cur");; | ||
esac | ||
} | ||
_accounts(){ | ||
local config | ||
|
||
config="$(pizauth info | awk -F' *: *' '$1 ~ /config file/ { print $2 }')" | ||
sed -n '/^account/{s/^account \(.*\) {/\1/;p}' "$config" | ||
} | ||
_pizauth() | ||
{ | ||
local cur prev sub | ||
local cmds=(dump info refresh restore reload server show shutdown status) | ||
|
||
cur=${COMP_WORDS[COMP_CWORD]} | ||
prev=${COMP_WORDS[COMP_CWORD - 1]} | ||
sub=${COMP_WORDS[1]} | ||
|
||
if [ "$sub" == server ] && [ "$COMP_CWORD" -gt 1 ]; then _server; return; fi | ||
|
||
case ${COMP_CWORD} in | ||
1) mapfile -t COMPREPLY < <(compgen -W "${cmds[*]}" -- "$cur");; | ||
2) | ||
case $sub in | ||
dump|restore|reload|shutdown|status) COMPREPLY=();; | ||
info) mapfile -t COMPREPLY < <(compgen -W '-j' -- "$cur") ;; | ||
refresh|show) | ||
local accounts | ||
mapfile -t accounts < <(_accounts) | ||
accounts+=(-u) | ||
mapfile -t COMPREPLY < \ | ||
<(compgen -W "${accounts[*]}" -- "$cur") | ||
;; | ||
esac | ||
;; | ||
3) | ||
case $sub in | ||
refresh|show) | ||
case $prev in | ||
-u) | ||
local accounts | ||
mapfile -t accounts < <(_accounts) | ||
mapfile -t COMPREPLY < \ | ||
<(compgen -W "${accounts[*]}" -- "$cur") | ||
;; | ||
*) COMPREPLY=() | ||
esac | ||
;; | ||
esac | ||
;; | ||
*) | ||
COMPREPLY=() | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _pizauth pizauth |