From 083bc1e5dd41cbc6b8847764908b4243f7629697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20St=C3=BCrz?= Date: Fri, 18 Mar 2022 20:37:50 +0100 Subject: [PATCH 1/3] Added bash shell-completion for mangohud. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added meson option: -Dbashcompletiondir= Signed-off-by: Benjamin Stürz --- data/meson.build | 2 ++ data/shell-completions/bash/mangohud | 22 ++++++++++++++++++++++ data/shell-completions/bash/meson.build | 13 +++++++++++++ meson_options.txt | 3 ++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 data/shell-completions/bash/mangohud create mode 100644 data/shell-completions/bash/meson.build diff --git a/data/meson.build b/data/meson.build index 2a77575c4a..665fc2bd5c 100644 --- a/data/meson.build +++ b/data/meson.build @@ -2,3 +2,5 @@ install_man( files('mangohud.1'), install_dir: join_paths(get_option('mandir'), 'man1'), ) + +subdir('shell-completions/bash') diff --git a/data/shell-completions/bash/mangohud b/data/shell-completions/bash/mangohud new file mode 100644 index 0000000000..3574c8888f --- /dev/null +++ b/data/shell-completions/bash/mangohud @@ -0,0 +1,22 @@ +# bash completion for mangohud(8) -*- 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 diff --git a/data/shell-completions/bash/meson.build b/data/shell-completions/bash/meson.build new file mode 100644 index 0000000000..deda03a6bc --- /dev/null +++ b/data/shell-completions/bash/meson.build @@ -0,0 +1,13 @@ +bashcompletiondir = get_option('bashcompletiondir') +if bashcompletiondir == '' + bash_completion = dependency('bash-completion', required: false) + if bash_completion.found() + bashcompletiondir = bash_completion.get_pkgconfig_variable('completionsdir') + else + bashcompletiondir = datadir / 'bash-completion/completions' + endif +endif + +if bashcompletiondir != 'no' + install_data('mangohud', install_dir: bashcompletiondir) +endif diff --git a/meson_options.txt b/meson_options.txt index 9744bc8f49..5b3d748171 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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]') 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') @@ -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') \ No newline at end of file +option('mangoapp_layer', type: 'boolean', value : 'false') From 61ec1ea56fbde15779ecb5e1266c2d45eb0be8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20St=C3=BCrz?= Date: Fri, 18 Mar 2022 21:13:45 +0100 Subject: [PATCH 2/3] bash-completion: Added mangohudctl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - And fixed mangohud completion Signed-off-by: Benjamin Stürz --- data/shell-completions/bash/mangohud | 2 +- data/shell-completions/bash/mangohudctl | 17 +++++++++++++++++ data/shell-completions/bash/meson.build | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 data/shell-completions/bash/mangohudctl diff --git a/data/shell-completions/bash/mangohud b/data/shell-completions/bash/mangohud index 3574c8888f..94f7002d37 100644 --- a/data/shell-completions/bash/mangohud +++ b/data/shell-completions/bash/mangohud @@ -1,4 +1,4 @@ -# bash completion for mangohud(8) -*- shell-script -*- +# bash completion for mangohud(1) -*- shell-script -*- _mangohud() { local cur prev words cword split diff --git a/data/shell-completions/bash/mangohudctl b/data/shell-completions/bash/mangohudctl new file mode 100644 index 0000000000..ce69d384fb --- /dev/null +++ b/data/shell-completions/bash/mangohudctl @@ -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 diff --git a/data/shell-completions/bash/meson.build b/data/shell-completions/bash/meson.build index deda03a6bc..ce39184e22 100644 --- a/data/shell-completions/bash/meson.build +++ b/data/shell-completions/bash/meson.build @@ -9,5 +9,6 @@ if bashcompletiondir == '' endif if bashcompletiondir != 'no' - install_data('mangohud', install_dir: bashcompletiondir) + install_data('mangohud', install_dir: bashcompletiondir) + install_data('mangohudctl', install_dir: bashcompletiondir) endif From cb4da793dc22f87e0c97a86b42cc859a015353bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20St=C3=BCrz?= Date: Fri, 18 Mar 2022 21:23:52 +0100 Subject: [PATCH 3/3] bash-completion: Fixed deprecation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Benjamin Stürz --- data/shell-completions/bash/meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/shell-completions/bash/meson.build b/data/shell-completions/bash/meson.build index ce39184e22..a3f520f6e2 100644 --- a/data/shell-completions/bash/meson.build +++ b/data/shell-completions/bash/meson.build @@ -1,10 +1,11 @@ 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_pkgconfig_variable('completionsdir') + bashcompletiondir = bash_completion.get_variable(pkgconfig: 'completionsdir', default_value: bashcompletion_defaultdir) else - bashcompletiondir = datadir / 'bash-completion/completions' + bashcompletiondir = bash_completion_defaultdir endif endif