diff options
Diffstat (limited to 'Completion')
-rw-r--r-- | Completion/Linux/Command/_modutils | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Completion/Linux/Command/_modutils b/Completion/Linux/Command/_modutils new file mode 100644 index 000000000..1b47e8a3d --- /dev/null +++ b/Completion/Linux/Command/_modutils @@ -0,0 +1,87 @@ +#compdef modprobe rmmod + +local curcontext="$curcontext" state line expl loaded + +_modutils_loaded_modules() { + +if [[ -r /proc/modules ]]; then + loaded=(${${(f)"$(</proc/modules)"}%% *}) +elif [[ -x /sbin/lsmod ]]; then + loaded=(${${(f)"$(/sbin/lsmod)"}[2,-1]%% *}) +else + return 1 +fi + +_wanted modules expl 'loaded module' compadd -a loaded +} + +case "$service" in + rmmod) + + _arguments '(--all)-a[remove all unused autocleanable modules]' \ + '(-a)--all' \ + '(--persist)-e[save persistent data]' \ + '(-e)--persist' \ + '(--help)-h[print help text]' \ + '(-h)--help' \ + '(--stacks)-r[remove a module stack]' \ + '(-r)--stacks' \ + '(--syslog)-s[output to syslog]' \ + '(-s)--syslog' \ + '(--verbose)-v[be verbose]' \ + '(-v)--verbose' \ + '(--version)-V[print version]' \ + '(-V)--version' \ + '*:loaded module:_modutils_loaded_modules' && return 0 + ;; + + modprobe) + + _modprobe_arguments=( + '(--all)-a[all]' \ + '(-a)--all' \ + '(--showconfig)-c[showconfig]' \ + '(-c)--showconfig' \ + '(--debug)-d[debug]' \ + '(-d)--debug' \ + '(--autoclean)-k[set autoclean]' \ + '(-k)--autoclean' \ + '(--show)-n[do not act]' \ + '(-n)--show' \ + '(--quiet)-q[do not complain about insmod failures]' \ + '(-q)--quiet' \ + '(--syslog)-s[report via syslog instead of stderr]' \ + '(-s)--syslog' \ + '(--type)-t[module type]:moduletype:' \ + '(-t)--type:moduletype:' \ + '(--verbose)-v[print all commands as executed]' \ + '(-v)--verbose' \ + '(--version)-V[show release version]' \ + '(-V)--version' \ + '(--config)-C[config file]:config file:_files' \ + '(-C)--config:config file:_files' + ) + + _arguments -C '(--remove)-r[remove]:*:loaded module:->modprobe_remove' \ + '(-r)--remove:*:loaded module:->modprobe_remove' \ + '(--list)-l[list matching modules]:*:module file:->modprobe_list' \ + '(-l)--list:*:module file:->modprobe_list' \ + "$_modprobe_arguments[@]" && return 0 + + ;; + +esac + +case "$state" in + modprobe_remove) + _call_function ret _modutils_$state && return ret + _arguments "$_modprobe_arguments[@]" \ + '*:loaded module:_modutils_loaded_modules' + ;; + + modprobe_list) + _call_function ret _modutils_$state && return ret + _arguments "$_modprobe_arguments[@]" \ + '*:module file:compadd ${^${(M)${(f)"$(modprobe -c)"}:#path*}#*[=]}/**/*.o(:t)' + +esac |