mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
Add eselect, rc-update and rc-service completions. (These are utilities used by Gentoo Linux)
Disable php completion for the 4th part of the command, since php-eselect is differently designed and causes errors Closes #1131.
This commit is contained in:
parent
9862eb930d
commit
44d13869ad
74
share/completions/eselect.fish
Normal file
74
share/completions/eselect.fish
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
function __fish_eselect_cmd
|
||||||
|
eselect --brief --colour=no $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_complete_eselect_modules
|
||||||
|
set -l sedregexp 's/^ ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
|
||||||
|
__fish_eselect_cmd modules list | sgrep '^ ' | sed -r $sedregexp
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_complete_eselect_actions
|
||||||
|
set -l sedregexp 's/^ ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
|
||||||
|
set -l cmdl (commandline -poc)
|
||||||
|
__fish_eselect_cmd $cmdl[2..-1] usage | sgrep '^ [^ -]' | sed -r $sedregexp
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_complete_eselect_action_options
|
||||||
|
set -l parseregexp 's/^ ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
|
||||||
|
set -l cmdl (commandline -poc)
|
||||||
|
|
||||||
|
# Disable further php completion
|
||||||
|
if [ (__fish_print_cmd_args_without_options)[2] = 'php' ]
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
switch $cmdl[-1]
|
||||||
|
case -'*'
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l findregexp '/^ '$cmdl[-1]'/,/^ [^ ]/p'
|
||||||
|
|
||||||
|
set cmdl[-1] usage
|
||||||
|
__fish_eselect_cmd $cmdl[2..-1] | sed -n -re $findregexp | sgrep '^ --' | sed -re $parseregexp
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_complete_eselect_targets
|
||||||
|
set -l sedregexp 's/^ \[([0-9]+)\][ ]*/\1\t/g'
|
||||||
|
set -l cmdl (commandline -poc)
|
||||||
|
|
||||||
|
# Disable further php completion
|
||||||
|
# https://github.com/fish-shell/fish-shell/pull/1131
|
||||||
|
if [ (__fish_print_cmd_args_without_options)[2] = 'php' ]
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
switch $cmdl[-1]
|
||||||
|
case -'*'
|
||||||
|
set cmdl[-2] list
|
||||||
|
case '*'
|
||||||
|
set cmdl[-1] list
|
||||||
|
end
|
||||||
|
|
||||||
|
eselect --colour=no $cmdl[2..-1] | sgrep '^ [^ -]' | sed -r $sedregexp
|
||||||
|
end
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
|
||||||
|
-xa '(__fish_complete_eselect_modules)'
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
|
||||||
|
-l brief -d 'Make output shorter'
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
|
||||||
|
-l colour \
|
||||||
|
-d "=<yes|no|auto> Enable or disable colour output (default 'auto')"
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 2" \
|
||||||
|
-xa '(__fish_complete_eselect_actions)'
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
|
||||||
|
-xa '(__fish_complete_eselect_targets)'
|
||||||
|
|
||||||
|
complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
|
||||||
|
-xa '(__fish_complete_eselect_action_options)'
|
||||||
|
|
20
share/completions/rc-service.fish
Normal file
20
share/completions/rc-service.fish
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# First argument is the names of the service, i.e. a file in /etc/init.d
|
||||||
|
complete -c rc-service -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
|
||||||
|
-xa "(__fish_print_service_names)" --description "Service name"
|
||||||
|
|
||||||
|
# The second argument is what action to take with the service
|
||||||
|
complete -c rc-service -n "test (__fish_number_of_cmd_args_wo_opts) -gt 1" \
|
||||||
|
-xa "(__fish_complete_service_actions)"
|
||||||
|
|
||||||
|
# Complete rc-service the options
|
||||||
|
complete -c rc-service -s e -l exists -d 'Tests if the service exists or not'
|
||||||
|
complete -c rc-service -s i -l ifexists \
|
||||||
|
-d 'If the service exists, then run the command'
|
||||||
|
complete -c rc-service -s l -l list -d 'List all available services'
|
||||||
|
complete -c rc-service -s r -l resolve \
|
||||||
|
-d 'Resolve the service name to an init script'
|
||||||
|
complete -c rc-service -s h -l help -d 'Display the help output'
|
||||||
|
complete -c rc-service -s C -l nocolor -d 'Disable color output'
|
||||||
|
complete -c rc-service -s V -l version -d 'Display software version'
|
||||||
|
complete -c rc-service -s v -l verbose -d 'Run verbosely'
|
||||||
|
complete -c rc-service -s q -l quiet -d 'Run quietly (Does not affect errors)'
|
33
share/completions/rc-update.fish
Normal file
33
share/completions/rc-update.fish
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
function __fish_complete_rc-update_actions
|
||||||
|
set -l actions add \
|
||||||
|
'Add the service to the runlevel or the current one if non given'
|
||||||
|
set -l actions $actions del \
|
||||||
|
'Delete the service from the runlevel or the current one if non given'
|
||||||
|
set -l actions $actions show \
|
||||||
|
'Show all enabled services and the runlevels they belong to'
|
||||||
|
printf "%s\t%s\n" $actions
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fish_complete_rc-update_runlevels
|
||||||
|
set -l levels sysinit \
|
||||||
|
'First startup runlevel' \
|
||||||
|
boot \
|
||||||
|
'Second startup runlevel' \
|
||||||
|
default \
|
||||||
|
'Last startup runlevel' \
|
||||||
|
shutdown \
|
||||||
|
'Runlevel for stutting down'
|
||||||
|
printf "%s\t%s\n" $levels
|
||||||
|
end
|
||||||
|
|
||||||
|
# The first argument is what action to take with the service
|
||||||
|
complete -c rc-update -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
|
||||||
|
-xa "(__fish_complete_rc-update_actions)"
|
||||||
|
|
||||||
|
# The second argument is the names of the service, i.e. a file in /etc/init.d
|
||||||
|
complete -c rc-update -n "test (__fish_number_of_cmd_args_wo_opts) = 2" \
|
||||||
|
-xa "(__fish_print_service_names)" --description "Service name"
|
||||||
|
|
||||||
|
# The third argument is the names of the service, i.e. a file in /etc/init.d
|
||||||
|
complete -c rc-update -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
|
||||||
|
-xa "(__fish_complete_rc-update_runlevels)"
|
|
@ -1,13 +1,5 @@
|
||||||
function __fish_service_print_names
|
|
||||||
if type -f systemctl >/dev/null
|
|
||||||
command systemctl list-units -t service | cut -d ' ' -f 1 | grep '\.service$' | sed -e 's/\.service$//'
|
|
||||||
end
|
|
||||||
|
|
||||||
command ls /etc/init.d
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fist argument is the names of the service, i.e. a file in /etc/init.d
|
# Fist argument is the names of the service, i.e. a file in /etc/init.d
|
||||||
complete -c service -n "test (count (commandline -poc)) = 1" -xa "(__fish_service_print_names)" --description "Service name"
|
complete -c service -n "test (count (commandline -poc)) = 1" -xa "(__fish_print_service_names)" --description "Service name"
|
||||||
|
|
||||||
#The second argument is what action to take with the service
|
#The second argument is what action to take with the service
|
||||||
complete -c service -n "test (count (commandline -poc)) -gt 1" -xa '$__fish_service_commands'
|
complete -c service -n "test (count (commandline -poc)) -gt 1" -xa '$__fish_service_commands'
|
||||||
|
|
7
share/functions/__fish_complete_service_actions.fish
Normal file
7
share/functions/__fish_complete_service_actions.fish
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
function __fish_complete_service_actions -d "Print a list of all basic service \
|
||||||
|
actions"
|
||||||
|
set -l actions start 'Start the service'
|
||||||
|
set -l actions $actions stop 'Stop the service'
|
||||||
|
set -l actions $actions restart 'Restart the service'
|
||||||
|
printf "%s\t%s\n" $actions
|
||||||
|
end
|
4
share/functions/__fish_number_of_cmd_args_wo_opts.fish
Normal file
4
share/functions/__fish_number_of_cmd_args_wo_opts.fish
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
function __fish_number_of_cmd_args_wo_opts
|
||||||
|
count (__fish_print_cmd_args_without_options)
|
||||||
|
end
|
||||||
|
|
3
share/functions/__fish_print_cmd_args.fish
Normal file
3
share/functions/__fish_print_cmd_args.fish
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function __fish_print_cmd_args
|
||||||
|
commandline -poc
|
||||||
|
end
|
|
@ -0,0 +1,3 @@
|
||||||
|
function __fish_print_cmd_args_without_options
|
||||||
|
__fish_print_cmd_args | grep '^[^-]'
|
||||||
|
end
|
10
share/functions/__fish_print_service_names.fish
Normal file
10
share/functions/__fish_print_service_names.fish
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
function __fish_print_service_names -d 'All services known to the system'
|
||||||
|
if type -f systemctl >/dev/null
|
||||||
|
command systemctl list-units -t service | cut -d ' ' -f 1 | grep '\.service$' | sed -e 's/\.service$//'
|
||||||
|
else if type -f rc-service
|
||||||
|
command rc-service -l
|
||||||
|
else
|
||||||
|
command ls /etc/init.d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user