83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# systemd-analyze(1) completion -*- shell-script -*-
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# This file is part of systemd.
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# Copyright 2010 Ran Benita
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# Copyright 2013 Harald Hoyer
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# systemd is free software; you can redistribute it and/or modify it
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# under the terms of the GNU Lesser General Public License as published by
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# the Free Software Foundation; either version 2.1 of the License, or
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# (at your option) any later version.
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# systemd is distributed in the hope that it will be useful, but
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# WITHOUT ANY WARRANTY; without even the implied warranty of
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# General Public License for more details.
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# You should have received a copy of the GNU Lesser General Public License
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer# along with systemd; If not, see <http://www.gnu.org/licenses/>.
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen__get_machines() {
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer_systemd_analyze() {
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer local i verb comps
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
20ba8107a598688e94b2927546718bc80f6514f1Evgeny Vereshchagin [STANDALONE]='--help --version --system --user --order --require --no-pager --man'
20ba8107a598688e94b2927546718bc80f6514f1Evgeny Vereshchagin [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern '
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer local -A VERBS=(
299c397c127cda34facbe7d089f944a708ec95e9Zbigniew Jędrzejewski-Szmek [STANDALONE]='time blame plot dump'
bb150966c0687d2fa94da0a36dabba90c1a84b8bHarald Hoyer [CRITICAL_CHAIN]='critical-chain'
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek [LOG_LEVEL]='set-log-level'
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek [VERIFY]='verify'
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer _init_completion || return
3ce09b7da2eb8b888066468663b2b5c81a05a03cZbigniew Jędrzejewski-Szmek for ((i=0; i < COMP_CWORD; i++)); do
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer verb=${COMP_WORDS[i]}
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen if __contains_word "$prev" ${OPTS[ARG]}; then
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen comps=$(compgen -A hostname)
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen comps=$( __get_machines )
64ae7f1864d54f38d62e258322a7ea9756c7284bThomas Hindoe Paaboel Andersen COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer if [[ -z $verb && $cur = -* ]]; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer if [[ -z $verb ]]; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer comps=${VERBS[*]}
299c397c127cda34facbe7d089f944a708ec95e9Zbigniew Jędrzejewski-Szmek elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer if [[ $cur = -* ]]; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer comps='--help --version --system --user'
bb150966c0687d2fa94da0a36dabba90c1a84b8bHarald Hoyer elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
bb150966c0687d2fa94da0a36dabba90c1a84b8bHarald Hoyer if [[ $cur = -* ]]; then
bb150966c0687d2fa94da0a36dabba90c1a84b8bHarald Hoyer comps='--help --version --system --user --fuzz'
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer elif __contains_word "$verb" ${VERBS[DOT]}; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer if [[ $cur = -* ]]; then
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer comps='--help --version --system --user --from-pattern --to-pattern --order --require'
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek if [[ $cur = -* ]]; then
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek comps='--help --version --system --user'
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek comps='debug info notice warning err crit alert emerg'
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek elif __contains_word "$verb" ${VERBS[VERIFY]}; then
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek if [[ $cur = -* ]]; then
20ba8107a598688e94b2927546718bc80f6514f1Evgeny Vereshchagin comps='--help --version --system --user --man'
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek comps=$( compgen -A file -- "$cur" )
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek compopt -o filenames
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyer COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
83cb95b530ca5ae17bd9249774940840a4bbb667Harald Hoyercomplete -F _systemd_analyze systemd-analyze