From a9053603fa8cf3840fa43de5ab632de5ca756515 Mon Sep 17 00:00:00 2001 From: Niels De Graef Date: Sat, 16 May 2020 15:34:31 +0200 Subject: [PATCH 1/3] Add a Bash completion file --- etc/bash_completion | 76 +++++++++++++++++++++++++++++++++++++++++++++ etc/meson.build | 22 +++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 etc/bash_completion diff --git a/etc/bash_completion b/etc/bash_completion new file mode 100644 index 0000000000..ea09863978 --- /dev/null +++ b/etc/bash_completion @@ -0,0 +1,76 @@ + +__gimp() +{ + COMPREPLY=() + local current="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + + # GIMP options, sorted alphabetically + # + # Note that we don't specify short options here, since they're quite unintuitive + options=( + "--as-new" + "--batch" + "--batch-interpreter" + "--console-messages" + "--debug-handlers" + "--dump-gimprc" + "--dump-gimprc-manpage" + "--dump-gimprc-system" + "--dump-pdb-procedures-deprecated" + "--g-fatal-warnings" + "--gimprc" + "--help" + "--help-all" + "--help-gegl" + "--help-gtk" + "--license" + "--new-instance" + "--no-cpu-accel" + "--no-data" + "--no-fonts" + "--no-interface" + "--no-shm" + "--no-splash" + "--pdb-compat-mode" + "--session" + "--show-playground" + "--stack-trace-mode" + "--system-gimprc" + "--verbose" + "--version" + ) + + # + # Different completions for specific options + # + case "${prev}" in + # Options that shouldn't be used in combination with something else + help | license | version) + return 0 + ;; + # Expect a filename + gimprc | session | system-gimprc) + COMPREPLY=( $(compgen -f -- ${current}) ) + return 0 + ;; + # Expect *some* argument, so don't complete + b | batch | display) + return 0 + ;; + batch-interpreter) + # FIXME: we should try to get the list of interpreters somehow + local interpreters=$(gimp --LIST_INTERPRETERS) + COMPREPLY=("python-fu-eval" "plug-in-script-fu-eval") + return 0 + ;; + *) + ;; + esac + + # Default: complete with either an option "-W" or a filename "-f" + COMPREPLY=($(compgen -W "${options[*]}" -f -- ${current})) + return 0 +} + +complete -F __gimp gimp diff --git a/etc/meson.build b/etc/meson.build index c4cae6f864..f9a574dfd0 100644 --- a/etc/meson.build +++ b/etc/meson.build @@ -19,3 +19,25 @@ install_data( ], install_dir: gimpsysconfdir, ) + +# Bash completion +have_bash = find_program('bash', required : false).found() # For completion scripts +bash_comp_dep = dependency('bash-completion', version: '>=2.0', required: false) +if have_bash + + bash_comp_inst_dir = '' + if bash_comp_dep.found() + bash_comp_dir_override = bash_comp_dep.version().version_compare('>= 2.10') ? ['datadir', get_option('datadir')] : ['prefix', get_option('prefix')] + bash_comp_inst_dir = bash_comp_dep.get_variable('completionsdir', define_variable: bash_comp_dir_override) + endif + + if bash_comp_inst_dir == '' + message('Found bash-completion but the .pc file did not set \'completionsdir\', fallback to a predefined path') + bash_comp_inst_dir = get_option('datadir') / 'bash-completion' / 'completions' + endif + + install_data('bash_completion', + install_dir: bash_comp_inst_dir, + rename: 'gimp', + ) +endif From 277e5124d298f20325bbd626a4a4258d035907fd Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 9 May 2025 22:51:46 +0200 Subject: [PATCH 2/3] etc: fix unknown meson option. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes: > […]/gimp/etc/meson.build:31:39: ERROR: dependency.get_variable got unknown keyword arguments "define_variable" This MR was years-old. Maybe this option got renamed since that time. --- etc/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/meson.build b/etc/meson.build index f9a574dfd0..74cb342897 100644 --- a/etc/meson.build +++ b/etc/meson.build @@ -28,7 +28,7 @@ if have_bash bash_comp_inst_dir = '' if bash_comp_dep.found() bash_comp_dir_override = bash_comp_dep.version().version_compare('>= 2.10') ? ['datadir', get_option('datadir')] : ['prefix', get_option('prefix')] - bash_comp_inst_dir = bash_comp_dep.get_variable('completionsdir', define_variable: bash_comp_dir_override) + bash_comp_inst_dir = bash_comp_dep.get_variable('completionsdir', pkgconfig_define: bash_comp_dir_override) endif if bash_comp_inst_dir == '' From c682d27c542df76a99e5b6c5ec0aca1cdada279e Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 9 May 2025 23:35:29 +0200 Subject: [PATCH 3/3] etc: make the new bash-completion file work for all variants of our executables. In particular make it also work with the `gimp-console` and with all symlink names. Also rename the bash completion file using the full application version so that it will be possible to install several such completion files side by side. --- etc/{bash_completion => bash_completion.in} | 18 ++++++++++++++++-- etc/meson.build | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) rename etc/{bash_completion => bash_completion.in} (82%) diff --git a/etc/bash_completion b/etc/bash_completion.in similarity index 82% rename from etc/bash_completion rename to etc/bash_completion.in index ea09863978..eb27cc5bad 100644 --- a/etc/bash_completion +++ b/etc/bash_completion.in @@ -1,4 +1,3 @@ - __gimp() { COMPREPLY=() @@ -73,4 +72,19 @@ __gimp() return 0 } -complete -F __gimp gimp +complete -F __gimp @GIMP_MAIN_EXE@ +if command -v @GIMP_SYMLINK1@ 2>&1 > /dev/null +then + complete -F __gimp @GIMP_SYMLINK1@ + complete -F __gimp @GIMP_SYMLINK2@ +fi + +if command -v @GIMP_CONSOLE_EXE@ 2>&1 > /dev/null +then + complete -F __gimp @GIMP_CONSOLE_EXE@ + if command -v @GIMP_CONSOLE_SYMLINK1@ 2>&1 > /dev/null + then + complete -F __gimp @GIMP_CONSOLE_SYMLINK1@ + complete -F __gimp @GIMP_CONSOLE_SYMLINK2@ + fi +fi diff --git a/etc/meson.build b/etc/meson.build index 74cb342897..a1a0bd8538 100644 --- a/etc/meson.build +++ b/etc/meson.build @@ -36,8 +36,18 @@ if have_bash bash_comp_inst_dir = get_option('datadir') / 'bash-completion' / 'completions' endif - install_data('bash_completion', - install_dir: bash_comp_inst_dir, - rename: 'gimp', - ) + bash_completion_conf = configuration_data() + bash_completion_conf.set('GIMP_MAIN_EXE', gimpmain_exe_name) + bash_completion_conf.set('GIMP_SYMLINK1', 'gimp-' + gimp_app_version_major.to_string()) + bash_completion_conf.set('GIMP_SYMLINK2', 'gimp') + + bash_completion_conf.set('GIMP_CONSOLE_EXE', gimpconsole_exe_name) + bash_completion_conf.set('GIMP_CONSOLE_SYMLINK1', 'gimp-console-' + gimp_app_version_major.to_string()) + bash_completion_conf.set('GIMP_CONSOLE_SYMLINK2', 'gimp-console') + + configure_file(input : 'bash_completion.in', + output: 'gimp-' + gimp_app_version, + configuration: bash_completion_conf, + install: true, + install_dir: bash_comp_inst_dir) endif