fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerFix stale name of --tokens-expand option33a9659cd

master
1.4 KiB25 linesraw
1# First argument is the names of the service, i.e. a file in /etc/init.d
2complete -c service -n "__fish_is_nth_token 1" -xa "(__fish_print_service_names)" -d Service
3
4# as found in __fish_print_service_names.fish
5if test -d /run/systemd/system # Systemd systems
6    complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop restart status enable disable"
7else if command -sq rc-service # OpenRC (Gentoo)
8    complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop restart"
9else if test -d /etc/init.d # SysV on Debian and other linuxen
10    complete -c service -n 'not __fish_is_nth_token 1' -xa "start stop --full-restart"
11else # FreeBSD
12    # Use the output of `service -v foo` to retrieve the list of service-specific verbs
13    complete -c service -n 'not __fish_is_nth_token 1' -xa "(__fish_complete_freebsd_service_actions)"
14end
15
16function __fish_complete_freebsd_service_actions
17    # Use the output of `service -v foo` to retrieve the list of service-specific verbs
18    # Output takes the form "[prefix1 prefix2 ..](cmd1 cmd2 cmd3)" where any combination
19    # of zero or one prefixe(s) and any one command is a valid verb.
20    set -l service_name (commandline --tokens-expanded --cut-at-cursor)[-1]
21    set -l results (service $service_name -v 2>| string match -r '\\[(.*)\\]\\((.*)\\)')
22    set -l prefixes "" (string split '|' -- $results[2])
23    set -l commands (string split '|' -- $results[3])
24    printf '%s\n' $prefixes$commands
25end