summaryrefslogtreecommitdiff
path: root/completions/chronyc
diff options
context:
space:
mode:
Diffstat (limited to 'completions/chronyc')
-rw-r--r--completions/chronyc52
1 files changed, 21 insertions, 31 deletions
diff --git a/completions/chronyc b/completions/chronyc
index 3544c753..ede6bb09 100644
--- a/completions/chronyc
+++ b/completions/chronyc
@@ -1,5 +1,16 @@
# chronyc(1) completion -*- shell-script -*-
+_chronyc_command_args()
+{
+ local -a args=( $( compgen -W "$( $1 help 2>/dev/null | \
+ awk '/^'$prev'\s[^ []/ { gsub("\\|", " ", $2); print $2 }' )" ) )
+ case $args in
+ \<address\>) _known_hosts_real "$cur" ;;
+ \<*) ;;
+ *) COMPREPLY+=( $( compgen -W '${args[@]}' -- "$cur" ) ) ;;
+ esac
+}
+
_chronyc()
{
local cur prev words cword
@@ -16,7 +27,7 @@ _chronyc()
esac
if [[ $cur == -* ]]; then
- COMPREPLY=( $( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) )
+ COMPREPLY=( $( compgen -W '$( _parse_usage "$1" ) -6' -- "$cur" ) )
return
fi
@@ -24,40 +35,19 @@ _chronyc()
for (( i=1; i < cword; i++ )); do
[[ ${words[i]} != -* && ${words[i-1]} != @(-p|-h) ]] && (( args++ ))
done
-
+
case $args in
0)
COMPREPLY=( $( compgen -W "$( $1 help 2>/dev/null | \
- awk 'NR > 1 { sub("\\|", " ", $1); print $1 }' )" -- "$cur" ) )
+ awk '!/(^ |: *$)/ { sub("\\|", " ", $1); print $1 }' )" \
+ -- "$cur" ) )
;;
1)
- case $prev in
- accheck|cmdaccheck|delete|maxdelay|maxdelayratio|\
- maxdelaydevratio|maxpoll|minpoll|minstratum|polltarget)
- _known_hosts_real "$cur"
- ;;
- add)
- COMPREPLY=( $( compgen -W 'peer server' -- "$cur" ) )
- ;;
- allow|cmdallow|cmddeny|deny)
- COMPREPLY=( $( compgen -W 'all' -- "$cur" ) )
- ;;
- authhash)
- COMPREPLY=( $( compgen -W 'MD5 SHA1' -- "$cur" ) )
- ;;
- dns)
- COMPREPLY=( $( compgen -W '-n +n -4 -6 -46' -- "$cur" ) )
- ;;
- local)
- COMPREPLY=( $( compgen -W 'off stratum' -- "$cur" ) )
- ;;
- manual)
- COMPREPLY=( $( compgen -W 'list on off reset' -- "$cur" ) )
- ;;
- sources|sourcestats)
- COMPREPLY=( $( compgen -W '-v' -- "$cur" ) )
- ;;
- esac
+ _chronyc_command_args "$1"
+ if [[ ! $COMPREPLY && $prev == sources?(tats) ]]; then
+ # [-v] not handled by _chronyc_command_args yet
+ COMPREPLY=( $( compgen -W '-v' -- "$cur" ) )
+ fi
;;
2)
[[ $prev == @(peer|server) ]] && _known_hosts_real "$cur"
@@ -66,4 +56,4 @@ _chronyc()
} &&
complete -F _chronyc chronyc
-# ex: ts=4 sw=4 et filetype=sh
+# ex: filetype=sh