| 1 |
# rmmod(8) completion -*- shell-script -*- |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
# |
| 4 |
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> |
| 5 |
# |
| 6 |
# Formatted using: |
| 7 |
# shfmt --language-dialect bash --indent 4 --func-next-line |
| 8 |
|
| 9 |
_rmmod() |
| 10 |
{ |
| 11 |
# long/short opt pairs |
| 12 |
local -A opts=( |
| 13 |
['force']='f' |
| 14 |
['syslog']='s' |
| 15 |
['verbose']='v' |
| 16 |
['version']='V' |
| 17 |
['help']='h' |
| 18 |
) |
| 19 |
|
| 20 |
local cur="${COMP_WORDS[COMP_CWORD]}" |
| 21 |
|
| 22 |
if [[ $cur == --* ]]; then |
| 23 |
COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}")) |
| 24 |
elif [[ $cur == -* ]]; then |
| 25 |
if (( ${#cur} != 2 )); then |
| 26 |
COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}")) |
| 27 |
fi |
| 28 |
COMPREPLY+=($(compgen -P '-' -W "${opts[*]}" -- "${cur:1}")) |
| 29 |
else |
| 30 |
local -a modules=($(lsmod | cut -f1 -d' ')) |
| 31 |
COMPREPLY=($(compgen -W "${modules[*]}" -- "${cur}")) |
| 32 |
fi |
| 33 |
} && |
| 34 |
complete -F _rmmod rmmod |