2018-06-18 11:03:02 +08:00
|
|
|
# First argument is the names of the service, i.e. a file in /etc/init.d
|
2022-02-09 16:46:07 +08:00
|
|
|
complete -c service -n "__fish_is_nth_token 1" -xa "(__fish_print_service_names)" -d Service
|
2018-06-13 08:24:18 +08:00
|
|
|
|
2018-06-04 12:05:04 +08:00
|
|
|
# as found in __fish_print_service_names.fish
|
|
|
|
if test -d /run/systemd/system # Systemd systems
|
2022-02-09 16:46:07 +08:00
|
|
|
complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop restart status enable disable"
|
2022-07-24 15:51:15 +08:00
|
|
|
else if command -sq rc-service # OpenRC (Gentoo)
|
2022-02-09 16:46:07 +08:00
|
|
|
complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop restart"
|
2018-06-04 12:05:04 +08:00
|
|
|
else if test -d /etc/init.d # SysV on Debian and other linuxen
|
2022-02-09 16:46:07 +08:00
|
|
|
complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop --full-restart"
|
2018-06-04 12:05:04 +08:00
|
|
|
else # FreeBSD
|
2019-05-05 18:53:09 +08:00
|
|
|
# Use the output of `service -v foo` to retrieve the list of service-specific verbs
|
2022-02-09 16:46:07 +08:00
|
|
|
complete -c service -n 'not __fish_is_nth_token 1' -xa "(__fish_complete_freebsd_service_actions)"
|
2018-06-18 10:48:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_complete_freebsd_service_actions
|
2019-05-05 18:53:09 +08:00
|
|
|
# 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
|
|
|
|
# of zero or one prefixe(s) and any one command is a valid verb.
|
2024-01-28 03:08:53 +08:00
|
|
|
set -l service_name (commandline --tokens-expanded --cut-at-cursor)[-1]
|
2019-05-05 18:53:09 +08:00
|
|
|
set -l results (service $service_name -v 2>| string match -r '\\[(.*)\\]\\((.*)\\)')
|
|
|
|
set -l prefixes "" (string split '|' -- $results[2])
|
|
|
|
set -l commands (string split '|' -- $results[3])
|
|
|
|
printf '%s\n' $prefixes$commands
|
2018-06-04 12:05:04 +08:00
|
|
|
end
|