-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shell-completion/*/rmmod: add bash/fish/zsh completion
v2: - use e(x)clusive answers for fish, tweak force string v3: - wire the completions to the autotools build v4: - use SPDX style copyright statements Signed-off-by: Emil Velikov <[email protected]> Link: #138 Signed-off-by: Lucas De Marchi <[email protected]>
- Loading branch information
1 parent
257034a
commit 76fbadb
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,7 @@ foreach tuple : _completiondirs | |
|
||
_completions = [ | ||
'lsmod', | ||
'rmmod', | ||
] | ||
|
||
if completiondir != 'no' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# rmmod(8) completion -*- shell-script -*- | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
# | ||
# Formatted using: | ||
# shfmt --language-dialect bash --indent 4 --func-next-line | ||
|
||
_rmmod() | ||
{ | ||
# long/short opt pairs | ||
local -A opts=( | ||
['force']='f' | ||
['syslog']='s' | ||
['verbose']='v' | ||
['version']='V' | ||
['help']='h' | ||
) | ||
|
||
local cur="${COMP_WORDS[COMP_CWORD]}" | ||
|
||
if [[ $cur == --* ]]; then | ||
COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}")) | ||
elif [[ $cur == -* ]]; then | ||
if (( ${#cur} != 2 )); then | ||
COMPREPLY=($(compgen -P '--' -W "${!opts[*]}" -- "${cur:2}")) | ||
fi | ||
COMPREPLY+=($(compgen -P '-' -W "${opts[*]}" -- "${cur:1}")) | ||
else | ||
local -a modules=($(lsmod | cut -f1 -d' ')) | ||
COMPREPLY=($(compgen -W "${modules[*]}" -- "${cur}")) | ||
fi | ||
} && | ||
complete -F _rmmod rmmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# rmmod(8) completion -*- shell-script -*- | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
|
||
# globally disable file completions | ||
complete -c rmmod -f | ||
|
||
complete -c rmmod -s f -l force -d "DANGEROUS: forces a module unload and may crash your machine" | ||
complete -c rmmod -s s -l syslog -d 'print to syslog, not stderr' | ||
complete -c rmmod -s v -l verbose -d 'enables more messages' | ||
complete -c rmmod -s V -l version -d 'show version' | ||
complete -c rmmod -s h -l help -d 'show this help' | ||
|
||
# provide an exclusive (x) list of required (r) answers (a) | ||
complete -c rmmod -x -ra "(lsmod | cut -f1 -d' ')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#compdef rmmod | ||
|
||
# rmmod(8) completion -*- shell-script -*- | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
|
||
(( $+functions[_rmmod_modules] )) || _rmmod_modules() | ||
{ | ||
local -a _modules | ||
_modules=(${${(f)"$(_call_program modules lsmod)"}[2,-1]%% *}) | ||
_values 'modules' "$_modules[@]" | ||
} | ||
|
||
_arguments \ | ||
{-f,--force}'[DANGEROUS: forces a module unload and may crash your machine]' \ | ||
{-s,--syslog}'[print to syslog, not stderr]' \ | ||
{-v,--verbose}'[enables more messages]' \ | ||
{-V,--version}'[show version]' \ | ||
{-h,--help}'[show this help]' \ | ||
'*::modules:_rmmod_modules' |