From 16e65c849cba3c62329dbf51b7e6b3e0654d8095 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 19 Feb 2015 16:29:41 +0100 Subject: [PATCH] systemctl completions: Only list matching units on enable/disable --- share/completions/systemctl.fish | 15 +++++++++++++-- .../functions/__fish_systemctl_service_paths.fish | 4 ++-- share/functions/__fish_systemctl_services.fish | 4 ++-- share/functions/__fish_systemctl_sockets.fish | 4 ++-- share/functions/__fish_systemctl_timers.fish | 4 ++-- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/share/completions/systemctl.fish b/share/completions/systemctl.fish index 26faa3b52..1e5be2ee7 100644 --- a/share/completions/systemctl.fish +++ b/share/completions/systemctl.fish @@ -6,7 +6,7 @@ set -l commands list-units list-sockets start stop reload restart try-restart re complete -f -e -c systemctl # All systemctl commands -complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a '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 show-environment set-environment unset-environment default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root' +complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a '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' #### Units commands complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a start -d 'Start one or more units' @@ -15,7 +15,7 @@ complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a resta complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a status -d 'Runtime status about one or more units' complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a enable -d 'Enable one or more units' complete -f -c systemctl -n "not __fish_seen_subcommand_from $commands" -a disable -d 'Disable one or more units' -for command in start stop restart status enable disable +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 status complete -f -c systemctl -n "__fish_seen_subcommand_from $command" -a '(__fish_systemctl_services)' -d 'Service' complete -f -c systemctl -n "__fish_seen_subcommand_from $command" -a '(__fish_systemctl_sockets)' -d 'Socket' complete -f -c systemctl -n "__fish_seen_subcommand_from $command" -a '(__fish_systemctl_mounts)' -d 'Mount' @@ -25,6 +25,17 @@ for command in start stop restart status enable disable complete -f -c systemctl -n "__fish_seen_subcommand_from $command" -a '(__fish_systemctl_timers)' -d 'Timer' end +# Enable/Disable: Only show units with matching state +complete -f -c systemctl -n "__fish_seen_subcommand_from enable" -a '(__fish_systemctl_services --state=disabled)' -d 'Service' +complete -f -c systemctl -n "__fish_seen_subcommand_from enable" -a '(__fish_systemctl_sockets --state=disabled)' -d 'Socket' +complete -f -c systemctl -n "__fish_seen_subcommand_from enable" -a '(__fish_systemctl_timers --state=disabled)' -d 'Timer' +complete -f -c systemctl -n "__fish_seen_subcommand_from enable" -a '(__fish_systemctl_service_paths --state=disabled)' -d 'Path' + +complete -f -c systemctl -n "__fish_seen_subcommand_from disable" -a '(__fish_systemctl_services --state=enabled)' -d 'Service' +complete -f -c systemctl -n "__fish_seen_subcommand_from disable" -a '(__fish_systemctl_sockets --state=enabled)' -d 'Socket' +complete -f -c systemctl -n "__fish_seen_subcommand_from disable" -a '(__fish_systemctl_timers --state=enabled)' -d 'Timer' +complete -f -c systemctl -n "__fish_seen_subcommand_from disable" -a '(__fish_systemctl_service_paths --state=enabled)' -d 'Path' + # These are useless for the other commands # .device in particular creates too much noise complete -f -c systemctl -n "__fish_seen_subcommand_from status" -a '(__fish_systemctl_devices)' -d 'Device' diff --git a/share/functions/__fish_systemctl_service_paths.fish b/share/functions/__fish_systemctl_service_paths.fish index 4c5d5ab51..5691ee0d0 100644 --- a/share/functions/__fish_systemctl_service_paths.fish +++ b/share/functions/__fish_systemctl_service_paths.fish @@ -1,9 +1,9 @@ function __fish_systemctl_service_paths if type -q systemctl if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=path ^/dev/null | cut -f 1 -d ' ' + systemctl --user list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' else - systemctl list-unit-files --no-legend --type=path ^/dev/null | cut -f 1 -d ' ' + systemctl list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' end end end diff --git a/share/functions/__fish_systemctl_services.fish b/share/functions/__fish_systemctl_services.fish index e047e6adf..847276b77 100644 --- a/share/functions/__fish_systemctl_services.fish +++ b/share/functions/__fish_systemctl_services.fish @@ -1,9 +1,9 @@ function __fish_systemctl_services if type -q systemctl if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' + systemctl --user list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' else - systemctl list-unit-files --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' + systemctl list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' end end end diff --git a/share/functions/__fish_systemctl_sockets.fish b/share/functions/__fish_systemctl_sockets.fish index f17541ef4..d45dfc1b3 100644 --- a/share/functions/__fish_systemctl_sockets.fish +++ b/share/functions/__fish_systemctl_sockets.fish @@ -1,9 +1,9 @@ function __fish_systemctl_sockets if type -q systemctl if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=socket ^/dev/null | cut -f 1 -d ' ' + systemctl --user list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' else - systemctl list-unit-files --no-legend --type=socket ^/dev/null | cut -f 1 -d ' ' + systemctl list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' end end end diff --git a/share/functions/__fish_systemctl_timers.fish b/share/functions/__fish_systemctl_timers.fish index fd828b6ea..1dea2dc18 100644 --- a/share/functions/__fish_systemctl_timers.fish +++ b/share/functions/__fish_systemctl_timers.fish @@ -1,9 +1,9 @@ function __fish_systemctl_timers if type -q systemctl if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=timer ^/dev/null | cut -f 1 -d ' ' + systemctl --user list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' else - systemctl list-unit-files --no-legend --type=timer ^/dev/null | cut -f 1 -d ' ' + systemctl list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' end end end