timedatectl revision a72d698d0d9ff9c158155b44cdc77376df31a317
d29201dd5328b88140ce050100693c501852657dChristian Maeder# timedatectl(1) completion -*- shell-script -*-
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# This file is part of systemd.
cacbb5e3100fb85d23d1614cace3a8662801f2e6Eugen Kuksa# Copyright 2010 Ran Benita
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# systemd is free software; you can redistribute it and/or modify it
cacbb5e3100fb85d23d1614cace3a8662801f2e6Eugen Kuksa# under the terms of the GNU Lesser General Public License as published by
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# the Free Software Foundation; either version 2.1 of the License, or
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# (at your option) any later version.
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc# systemd is distributed in the hope that it will be useful, but
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# WITHOUT ANY WARRANTY; without even the implied warranty of
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# General Public License for more details.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# You should have received a copy of the GNU Lesser General Public License
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder# along with systemd; If not, see <http://www.gnu.org/licenses/>.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder__contains_word () {
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc local w word=$1; shift
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc for w in "$@"; do
6342ef8f9f785e79c91f217c30b3ba2b6fa0ad4fEugen Kuksa [[ $w = "$word" ]] && return
52c81e62d4a3797b926fb3392369b45a9fef336cSoeren D. Schulze_timedatectl() {
d386b61802c70e3d220d4520d9fcdefbd9c469f4Soeren D. Schulze local i verb comps
66977d201b3ff7ee9c1f992c0f3f701b69eac2c9Karl Luc local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
0ac66bed6456d7900a657269e36107ca7bec4756Iulia Ignatov local OPTS='-h --help --version --adjust-system-clock --no-pager
0ac66bed6456d7900a657269e36107ca7bec4756Iulia Ignatov --no-ask-password -H --host'
99a1bfbb82c875580410b4745617fea2297fdc2bEugen Kuksa if __contains_word "$prev" $OPTS; then
a35bacbc16daf5c10f9accfdfadc4971e9d6f648Iulia Ignatov case $prev in
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
3831cf8a3b0ea144a80d13fe0314cc2752e32107Christian Maeder if [[ $cur = -* ]]; then
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc local -A VERBS=(
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc [BOOLEAN]='set-local-rtc set-ntp'
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc [STANDALONE]='status set-time list-timezones'
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc [TIMEZONES]='set-timezone'
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc [TIME]='set-time'
1ea7fb6b0f66210bc0d3cb995f1b655277b33884Eugen Kuksa for ((i=0; i <= COMP_CWORD; i++)); do
d6ce032cac688f3698be7133d27f53d3967e6749Christian Maeder if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc verb=${COMP_WORDS[i]}
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc if [[ -z $verb ]]; then
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc comps=${VERBS[*]}
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
59ec6aa4da4c93d0d4ef53ed74fdf866d0654539Eugen Kuksa comps='true false'
59ec6aa4da4c93d0d4ef53ed74fdf866d0654539Eugen Kuksa elif __contains_word "$verb" ${VERBS[TIMEZONES]}; then
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc comps=$(command timedatectl list-timezones)
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[TIME]}; then
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luccomplete -F _timedatectl timedatectl