Skip to content

Commit

Permalink
Merge branch 'bbczeuz-zseng_dev_completion'
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Jun 17, 2016
2 parents c5d66ea + c05f8fd commit 6f302db
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions usr/share/bash-completion/completions/kapacitor
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Bash completion for the kapacitor command.
_kapacitor()
{
Expand Down Expand Up @@ -49,7 +48,7 @@ _kapacitor()
words=$(_kapacitor_dbrps)
;;
-tick)
COMPREPLY=($(compgen -o filenames -A file -X '!*.tick' -- "$cur"))
_kapacitor_tick_files "${cur}"
;;
-type)
words='batch stream'
Expand All @@ -58,7 +57,7 @@ _kapacitor()
words=$(_kapacitor_list templates "$cur")
;;
-vars)
COMPREPLY=($(compgen -o filenames -A file -- "$cur"))
_kapacitor_json_files "${cur}"
;;
*)
words='-dbrp -no-reload -tick -type -template -vars'
Expand All @@ -73,7 +72,7 @@ _kapacitor()
else
case "$prev" in
-tick)
COMPREPLY=($(compgen -o filenames -A file -X '!*.tick' -- "$cur"))
_kapacitor_tick_files "${cur}"
;;
-type)
words='batch stream'
Expand Down Expand Up @@ -165,6 +164,38 @@ _kapacitor()
return 0
}

_kapacitor_files_add_postfix()
{
#Add a slash (directories) or space (files except directories) after name
local c i=0
for c in "${COMPREPLY[@]}"; do
if [ -d "${c}" ]; then
COMPREPLY[i++]="${c}/";
else
COMPREPLY[i++]="${c} ";
fi
done
compopt -o nospace
}

_kapacitor_tick_files()
{
local didi cur="$1"
COMPREPLY=($(compgen -o filenames -f -X '!*.tick' -- "$cur") )
didi=$(compgen -d -- "$cur")
COMPREPLY=(${COMPREPLY[@]:-} $didi )
_kapacitor_files_add_postfix
}

_kapacitor_json_files()
{
local didi cur="$1"
COMPREPLY=($(compgen -o filenames -f -X '!*.json' -- "$cur") )
didi=$(compgen -d -- "$cur")
COMPREPLY=(${COMPREPLY[@]:-} $didi )
_kapacitor_files_add_postfix
}

_kapacitor_list()
{
# List a certain kind of object and return a set of IDs
Expand Down

0 comments on commit 6f302db

Please sign in to comment.