From 072974ec5c9d8d39041fe733d69d3ce37121cd69 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 17 Jun 2018 22:03:02 -0500 Subject: [PATCH] Fix service completions on non-FreeBSD platforms I never realized script-local variables set after the function definition do not keep their value when the function is executed later in the file. --- share/completions/service.fish | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/share/completions/service.fish b/share/completions/service.fish index 9d85bc1ec..2c5a1d64f 100644 --- a/share/completions/service.fish +++ b/share/completions/service.fish @@ -1,29 +1,28 @@ -# Fist argument is the names of the service, i.e. a file in /etc/init.d -complete -c service -n "__fish_is_first_token" -xa "(__fish_print_service_names)" -d "Service name" +# First argument is the names of the service, i.e. a file in /etc/init.d +complete -c service -n "__fish_is_first_token" -xa "(__fish_print_service_names)" -d "Service" set -l service_commands +function __fish_complete_static_service_actions + #The second argument is what action to take with the service + complete -c service -n "not __fish_is_first_token" -xa "$argv" +end # as found in __fish_print_service_names.fish if test -d /run/systemd/system # Systemd systems set service_commands start stop restart status enable disable - __fish_complete_static_service_actions + __fish_complete_static_service_actions $service_commands else if type -f rc-service 2>/dev/null # OpenRC (Gentoo) set service_commands start stop restart - __fish_complete_static_service_actions + __fish_complete_static_service_actions $service_commands else if test -d /etc/init.d # SysV on Debian and other linuxen set service_commands start stop "--full-restart" - __fish_complete_static_service_actions + __fish_complete_static_service_actions $service_commands else # FreeBSD # Use the output of `service -v foo` to retrieve the list of service-specific verbs # We can safely use `sed` here because this is platform-specific complete -c service -n "not __fish_is_first_token" -xa "(__fish_complete_freebsd_service_actions)" end -function __fish_complete_static_service_actions - #The second argument is what action to take with the service - complete -c service -n "not __fish_is_first_token" -xa "$service_commands" -end - function __fish_complete_freebsd_service_actions # Use the output of `service -v foo` to retrieve the list of service-specific verbs # Output takes the form "[prefix1 prefix2 ..](cmd1 cmd2 cmd3)" where any combination