aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--share/completions/eselect.fish74
-rw-r--r--share/completions/rc-service.fish20
-rw-r--r--share/completions/rc-update.fish33
-rw-r--r--share/completions/service.fish10
-rw-r--r--share/functions/__fish_complete_service_actions.fish7
-rw-r--r--share/functions/__fish_number_of_cmd_args_wo_opts.fish4
-rw-r--r--share/functions/__fish_print_cmd_args.fish3
-rw-r--r--share/functions/__fish_print_cmd_args_without_options.fish3
-rw-r--r--share/functions/__fish_print_service_names.fish10
9 files changed, 155 insertions, 9 deletions
diff --git a/share/completions/eselect.fish b/share/completions/eselect.fish
new file mode 100644
index 00000000..5ecdcd6f
--- /dev/null
+++ b/share/completions/eselect.fish
@@ -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)'
+
diff --git a/share/completions/rc-service.fish b/share/completions/rc-service.fish
new file mode 100644
index 00000000..a8885686
--- /dev/null
+++ b/share/completions/rc-service.fish
@@ -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)'
diff --git a/share/completions/rc-update.fish b/share/completions/rc-update.fish
new file mode 100644
index 00000000..f2339699
--- /dev/null
+++ b/share/completions/rc-update.fish
@@ -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)"
diff --git a/share/completions/service.fish b/share/completions/service.fish
index 2f361437..4914f97b 100644
--- a/share/completions/service.fish
+++ b/share/completions/service.fish
@@ -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
-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
complete -c service -n "test (count (commandline -poc)) -gt 1" -xa '$__fish_service_commands'
diff --git a/share/functions/__fish_complete_service_actions.fish b/share/functions/__fish_complete_service_actions.fish
new file mode 100644
index 00000000..ab91f786
--- /dev/null
+++ b/share/functions/__fish_complete_service_actions.fish
@@ -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
diff --git a/share/functions/__fish_number_of_cmd_args_wo_opts.fish b/share/functions/__fish_number_of_cmd_args_wo_opts.fish
new file mode 100644
index 00000000..83e3d2fa
--- /dev/null
+++ b/share/functions/__fish_number_of_cmd_args_wo_opts.fish
@@ -0,0 +1,4 @@
+function __fish_number_of_cmd_args_wo_opts
+ count (__fish_print_cmd_args_without_options)
+end
+
diff --git a/share/functions/__fish_print_cmd_args.fish b/share/functions/__fish_print_cmd_args.fish
new file mode 100644
index 00000000..eaafe65a
--- /dev/null
+++ b/share/functions/__fish_print_cmd_args.fish
@@ -0,0 +1,3 @@
+function __fish_print_cmd_args
+ commandline -poc
+end
diff --git a/share/functions/__fish_print_cmd_args_without_options.fish b/share/functions/__fish_print_cmd_args_without_options.fish
new file mode 100644
index 00000000..dadabc2a
--- /dev/null
+++ b/share/functions/__fish_print_cmd_args_without_options.fish
@@ -0,0 +1,3 @@
+function __fish_print_cmd_args_without_options
+ __fish_print_cmd_args | grep '^[^-]'
+end
diff --git a/share/functions/__fish_print_service_names.fish b/share/functions/__fish_print_service_names.fish
new file mode 100644
index 00000000..3eeb0015
--- /dev/null
+++ b/share/functions/__fish_print_service_names.fish
@@ -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
+