timedatectl revision a72d698d0d9ff9c158155b44cdc77376df31a317
d29201dd5328b88140ce050100693c501852657dChristian Maeder# timedatectl(1) completion -*- shell-script -*-
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder#
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder# This file is part of systemd.
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc#
cacbb5e3100fb85d23d1614cace3a8662801f2e6Eugen Kuksa# Copyright 2010 Ran Benita
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu#
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.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder#
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#
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/>.
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder__contains_word () {
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc local w word=$1; shift
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc for w in "$@"; do
6342ef8f9f785e79c91f217c30b3ba2b6fa0ad4fEugen Kuksa [[ $w = "$word" ]] && return
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc done
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc}
52c81e62d4a3797b926fb3392369b45a9fef336cSoeren D. Schulze
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'
0ac66bed6456d7900a657269e36107ca7bec4756Iulia Ignatov
99a1bfbb82c875580410b4745617fea2297fdc2bEugen Kuksa if __contains_word "$prev" $OPTS; then
a35bacbc16daf5c10f9accfdfadc4971e9d6f648Iulia Ignatov case $prev in
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder --host|-H)
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder comps=''
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder ;;
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder esac
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder return 0
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder fi
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder
3831cf8a3b0ea144a80d13fe0314cc2752e32107Christian Maeder if [[ $cur = -* ]]; then
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc return 0
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc fi
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc
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'
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc )
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc
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]}
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc break
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc fi
551f1476dea3f969775527cb15fd512e86279307Karl Luc done
9e5811a3323b00d6ff8d3fe91a185de1ab31150bChristian Maeder
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
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder comps=''
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder fi
e16b3696b2c173aac14200321868ed81b8f7dc69Christian Maeder
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc return 0
037be4e5b0e867dd148db2ea89640d8edf009053Eugen Kuksa}
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luc
75067b1beba1380cde707c30e7fc050d86f6927fKarl Luccomplete -F _timedatectl timedatectl
0b282d1269b8f9a658f7ce9090575ba1b00e8d66Christian Maeder