Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell completion for mangohud & mangohudctl #710

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ install_man(
files('mangohud.1'),
install_dir: join_paths(get_option('mandir'), 'man1'),
)

subdir('shell-completions/bash')
22 changes: 22 additions & 0 deletions data/shell-completions/bash/mangohud
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# bash completion for mangohud(1) -*- shell-script -*-

_mangohud() {
local cur prev words cword split
_init_completion -s || return

for (( i = 1; i <= cword; i++ )); do
if [[ ${words[i]} != -* ]]; then
local root_command=${words[i]}
_command_offset "$i"
return
fi
done

$split && return

if [[ $cur == -* ]]; then
COMPREPLY=(--dlsym)
return
fi
} &&
complete -F _mangohud mangohud
17 changes: 17 additions & 0 deletions data/shell-completions/bash/mangohudctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# bash completion for mangohudctl(1) -*- shell-script -*-

_mangohudctl() {
local cur prev words cword split
_init_completion -s || return

$split && return

if [[ $cword == 1 ]]; then
COMPREPLY=( $(compgen -W "set toggle" -- $cur) )
elif [[ $cword == 2 ]]; then
COMPREPLY=( $(compgen -W "$(mangohudctl 2>&1 | sed -n '/^Usage/d;/Attributes:/d;/Accepted/q;s/\s\+//;s/\s\+.*$//;p')" -- $cur) )
elif [[ $cword == 3 && ${words[1]} == set ]]; then
COMPREPLY=( $(compgen -W "true false" -- $cur) )
fi
} &&
complete -F _mangohudctl mangohudctl
15 changes: 15 additions & 0 deletions data/shell-completions/bash/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bashcompletiondir = get_option('bashcompletiondir')
if bashcompletiondir == ''
bash_completion = dependency('bash-completion', required: false)
bashcompletion_defaultdir = get_option('prefix') / get_option('datadir') / 'bash-completion/completions'
if bash_completion.found()
bashcompletiondir = bash_completion.get_variable(pkgconfig: 'completionsdir', default_value: bashcompletion_defaultdir)
else
bashcompletiondir = bash_completion_defaultdir
endif
endif

if bashcompletiondir != 'no'
install_data('mangohud', install_dir: bashcompletiondir)
install_data('mangohudctl', install_dir: bashcompletiondir)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add install_tag: 'scripts' for these install_datas?
Or some better tag though I already tagged mangohud with it :P

endif
3 changes: 2 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ option('glibcxx_asserts', type : 'boolean', value : false)
option('use_system_vulkan', type : 'feature', value : 'disabled', description: 'Use system vulkan headers instead of the provided ones')
option('use_system_spdlog', type : 'feature', value : 'disabled', description: 'Use system spdlog library')
option('vulkan_datadir', type : 'string', value : '', description: 'Path to the system vulkan headers data directory if different from MangoHud\'s datadir')
option('bashcompletiondir', type: 'string', description: 'Directory for bash completion script ["no" disables]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO the extra toggle is an overkill. The completion files are not even 50 lines in total, so I'd just install them always.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option specifies where to put the bash completions.
It may not be always in ${prefix}/share/bash-completion.
It just happens to allow disabling it.
I copied it from systemd's meson config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing logic will work with virtually any linux distro, even ones like Yocto. So in practical terms, the toggle is used for disabling the lot.

The fragment looked oddly familiar - thanks for confirming it's systemd origin.

option('append_libdir_mangohud', type : 'boolean', value : true, description: 'Append "mangohud" to libdir path or not.')
option('ld_libdir_prefix', type : 'boolean', value : false, description: 'Set ld libdir to "$prefix/lib/mangohud/\$LIB"')
option('ld_libdir_abs', type : 'boolean', value : false, description: 'Use absolute path in LD_PRELOAD')
Expand All @@ -16,4 +17,4 @@ option('with_dlsym', type : 'feature', value : 'disabled')
option('loglevel', type: 'combo', choices : ['trace', 'debug', 'info', 'warn', 'err', 'critical', 'off'], value : 'info', description: 'Max log level in non-debug build')
option('mangoapp', type: 'boolean', value : 'false')
option('mangohudctl', type: 'boolean', value : 'false')
option('mangoapp_layer', type: 'boolean', value : 'false')
option('mangoapp_layer', type: 'boolean', value : 'false')