summaryrefslogtreecommitdiff
path: root/src/grp-timedate
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-08-07 21:03:44 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-08-07 21:03:44 -0400
commit2abe0f2d527c7b3f6b97bd6519bf0e35a266ea68 (patch)
tree02eb54ce46d51f11defb2c6481cd23ee006d39c0 /src/grp-timedate
parent09010ac6999db43e39cde92200fc4a10858f5c51 (diff)
stuff
Diffstat (limited to 'src/grp-timedate')
-rw-r--r--src/grp-timedate/timedatectl/timedatectl.completion.bash76
-rw-r--r--src/grp-timedate/timedatectl/timedatectl.completion.zsh66
2 files changed, 142 insertions, 0 deletions
diff --git a/src/grp-timedate/timedatectl/timedatectl.completion.bash b/src/grp-timedate/timedatectl/timedatectl.completion.bash
new file mode 100644
index 0000000000..a57fbd2546
--- /dev/null
+++ b/src/grp-timedate/timedatectl/timedatectl.completion.bash
@@ -0,0 +1,76 @@
+# timedatectl(1) completion -*- shell-script -*-
+#
+# This file is part of systemd.
+#
+# Copyright 2010 Ran Benita
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
+__contains_word () {
+ local w word=$1; shift
+ for w in "$@"; do
+ [[ $w = "$word" ]] && return
+ done
+}
+
+_timedatectl() {
+ local i verb comps
+ local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
+ local OPTS='-h --help --version --adjust-system-clock --no-pager
+ --no-ask-password -H --host --machine'
+
+ if __contains_word "$prev" $OPTS; then
+ case $prev in
+ --host|-H)
+ comps=''
+ ;;
+ esac
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+ fi
+
+ if [[ $cur = -* ]]; then
+ COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
+ return 0
+ fi
+
+ local -A VERBS=(
+ [BOOLEAN]='set-local-rtc set-ntp'
+ [STANDALONE]='status set-time list-timezones'
+ [TIMEZONES]='set-timezone'
+ [TIME]='set-time'
+ )
+
+ for ((i=0; i < COMP_CWORD; i++)); do
+ if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
+ verb=${COMP_WORDS[i]}
+ break
+ fi
+ done
+
+ if [[ -z $verb ]]; then
+ comps=${VERBS[*]}
+ elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
+ comps='true false'
+ elif __contains_word "$verb" ${VERBS[TIMEZONES]}; then
+ comps=$(command timedatectl list-timezones)
+ elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[TIME]}; then
+ comps=''
+ fi
+
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ return 0
+}
+
+complete -F _timedatectl timedatectl
diff --git a/src/grp-timedate/timedatectl/timedatectl.completion.zsh b/src/grp-timedate/timedatectl/timedatectl.completion.zsh
new file mode 100644
index 0000000000..dfdcfebb3c
--- /dev/null
+++ b/src/grp-timedate/timedatectl/timedatectl.completion.zsh
@@ -0,0 +1,66 @@
+#compdef timedatectl
+
+_timedatectl_set-timezone(){
+ local -a _timezones
+ _timezones=( ${(f)"$(_call_program timezones "${service}" list-timezones)"} )
+ compadd "$_timezones[@]"
+}
+
+_timedatectl_set-time(){
+ _message "YYYY-MM-DD HH:MM:SS"
+}
+
+_timedatectl_set-local-rtc(){
+ local -a _options
+ _options=(
+ '0:Maintain RTC in universal time'
+ '1:Maintain RTC in local time'
+ )
+ _describe options _options
+}
+
+_timedatectl_set-ntp(){
+ local -a _options
+ _options=(
+ '0:Disable NTP based network time configuration'
+ '1:Enable NTP based network time configuration'
+ )
+ _describe options _options
+}
+
+_timedatectl_command(){
+ local -a _timedatectl_cmds
+ _timedatectl_cmds=(
+ 'status:Show current time settings'
+ 'set-time:Set system time'
+ 'set-timezone:Set system timezone'
+ 'list-timezones:Show known timezones'
+ 'set-local-rtc:Control whether RTC is in local time'
+ 'set-ntp:Control whether NTP is enabled'
+ )
+ if (( CURRENT == 1 )); then
+ _describe -t commands 'timedatectl command' _timedatectl_cmds
+ else
+ local curcontext="$curcontext"
+ cmd="${${_timedatectl_cmds[(r)$words[1]:*]%%:*}}"
+ if (( $#cmd )); then
+ if (( $+functions[_timedatectl_$cmd] )); then
+ _timedatectl_$cmd
+ else
+ _message "no more options"
+ fi
+ else
+ _message "unknown timedatectl command: $words[1]"
+ fi
+ fi
+}
+
+_arguments -s \
+ {-h,--help}'[Show this help]' \
+ '--version[Show package version]' \
+ '--adjust-system-clock[Adjust system clock when changing local RTC mode]' \
+ '--no-pager[Do not pipe output into a pager]' \
+ '--no-ask-password[Do not prompt for password]' \
+ {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
+ {-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
+ '*::timedatectl commands:_timedatectl_command'