-
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/*/lsmod: add bash/fish/zsh completion
Note that completions are explicitly aimed to be simple, depending on as little as possible shell specific helpers. The goal is that people unfamiliar with these can extend them with zero ramp-up. Doing things efficiently or "properly" is somewhat secondary. v2: - wire the completions to the autotools build v3: - 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
df6ef60
commit 257034a
Showing
7 changed files
with
133 additions
and
11 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
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 |
---|---|---|
|
@@ -191,16 +191,45 @@ if moduledir == '' | |
endif | ||
cdata.set_quoted('MODULE_DIRECTORY', moduledir) | ||
|
||
bashcompletiondir = get_option('bashcompletiondir') | ||
if bashcompletiondir == '' | ||
bashcompletion = dependency('bash-completion', required : false) | ||
if bashcompletion.found() | ||
bashcompletiondir = bashcompletion.get_variable(pkgconfig : 'completionsdir') | ||
else | ||
bashcompletiondir = join_paths(get_option('prefix'), get_option('datadir'), | ||
'bash-completion/completions') | ||
_completiondirs = [ | ||
['bashcompletiondir', 'bash-completion', 'bash-completion/completions', 'shell-completion/bash/@0@'], | ||
['fishcompletiondir', 'fish', 'fish/vendor_functions.d', 'shell-completion/fish/@[email protected]'], | ||
['zshcompletiondir', '', 'zsh/site-functions', 'shell-completion/zsh/_@0@'], | ||
] | ||
|
||
foreach tuple : _completiondirs | ||
dir_option = tuple[0] | ||
pkg_dep = tuple[1] | ||
def_path = tuple[2] | ||
ins_path = tuple[3] | ||
|
||
completiondir = get_option(dir_option) | ||
if completiondir == '' | ||
completion = dependency(pkg_dep, required : false) | ||
if completion.found() | ||
completiondir = completion.get_variable(pkgconfig : 'completionsdir') | ||
else | ||
completiondir = join_paths(get_option('prefix'), get_option('datadir'), | ||
def_path) | ||
endif | ||
endif | ||
endif | ||
|
||
_completions = [ | ||
'lsmod', | ||
] | ||
|
||
if completiondir != 'no' | ||
foreach comp : _completions | ||
install_data( | ||
files(ins_path.format(comp)), | ||
install_dir : completiondir, | ||
) | ||
endforeach | ||
endif | ||
|
||
# NEEDED solely for bash/kmod below | ||
set_variable(dir_option, completiondir) | ||
endforeach | ||
|
||
if bashcompletiondir != 'no' | ||
install_data( | ||
|
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# lsmod(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 | ||
|
||
_lsmod() | ||
{ | ||
# long/short opt pairs | ||
local -A opts=( | ||
['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}")) | ||
fi | ||
} && | ||
complete -F _lsmod lsmod |
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,12 @@ | ||
# lsmod(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 lsmod -f | ||
|
||
complete -c lsmod -s s -l syslog -d 'print to syslog, not stderr' | ||
complete -c lsmod -s v -l verbose -d 'enables more messages' | ||
complete -c lsmod -s V -l version -d 'show version' | ||
complete -c lsmod -s h -l help -d 'show this help' |
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,12 @@ | ||
#compdef lsmod | ||
|
||
# lsmod(8) completion -*- shell-script -*- | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# SPDX-FileCopyrightText: 2024 Emil Velikov <[email protected]> | ||
|
||
_arguments \ | ||
{-s,--syslog}'[print to syslog, not stderr]' \ | ||
{-v,--verbose}'[enables more messages]' \ | ||
{-V,--version}'[show version]' \ | ||
{-h,--help}'[show this help]' |