From fab4399b8c11b97dc04744c90841f57d5497de26 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 25 Jan 2017 01:14:38 +0100 Subject: [PATCH] available completions for systemctl depends on its current version --- share/completions/systemctl.fish | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/share/completions/systemctl.fish b/share/completions/systemctl.fish index d6a84e9cb..216cd5ce4 100644 --- a/share/completions/systemctl.fish +++ b/share/completions/systemctl.fish @@ -1,8 +1,15 @@ +set -l systemd_version (systemctl --version | head -n 1 | cut -f 2 -d ' ') set -l commands list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart \ isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help \ reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump \ list-dependencies snapshot delete daemon-reload daemon-reexec show-environment set-environment unset-environment \ - default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root cat edit + default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root +if test $systemd_version -gt 208 + set commands $commands cat + if test $systemd_version -gt 217 + set commands $commands edit + end +end set -l types services sockets mounts service_paths targets automounts timers function __fish_systemd_properties @@ -45,9 +52,19 @@ complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a enabl complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a disable -d 'Disable one or more units' complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a isolate -d 'Start a unit and dependencies and disable all others' complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a set-default -d 'Set the default target to boot into' -complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a cat -d 'Show an unit' -complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a edit -d 'Edit an unit' -for command in start stop restart try-restart reload-or-restart reload-or-try-restart is-active is-failed is-enabled reenable mask loaded link list-dependencies show cat edit status + +set -l commands_types start stop restart try-restart reload-or-restart reload-or-try-restart is-active is-failed is-enabled reenable mask loaded link list-dependencies show status + +if test $systemd_version -gt 208 + complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a cat -d 'Show an unit' + set commands_types $commands_types cat + if test $systemd_version -gt 217 + complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a edit -d 'Edit an unit' + set commands_types $commands_types edit + end +end + +for command in $commands_types for t in $types complete -f -c systemctl -n "__fish_seen_subcommand_from $command" -a "(eval __fish_systemctl_$t)" end @@ -114,6 +131,8 @@ complete -f -c systemctl -l version -d 'Print a short version and exit' complete -f -c systemctl -l no-pager -d 'Do not pipe output into a pager' # New options since systemd 220 -complete -f -c systemctl -l firmware-setup -n "__fish_seen_subcommand_from reboot" -d "Reboot to EFI setup" -complete -f -c systemctl -l now -n "__fish_seen_subcommand_from enable" -d "Also start unit" -complete -f -c systemctl -l now -n "__fish_seen_subcommand_from disable mask" -d "Also stop unit" +if test $systemd_version -gt 219 + complete -f -c systemctl -l firmware-setup -n "__fish_seen_subcommand_from reboot" -d "Reboot to EFI setup" + complete -f -c systemctl -l now -n "__fish_seen_subcommand_from enable" -d "Also start unit" + complete -f -c systemctl -l now -n "__fish_seen_subcommand_from disable mask" -d "Also stop unit" +end