[gimp/wip/nielsdg/bash-completion: 2834/2834] Add a Bash completion file
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/nielsdg/bash-completion: 2834/2834] Add a Bash completion file
- Date: Sat, 28 May 2022 11:42:40 +0000 (UTC)
commit 8b944fd113805721a833d58f727111bb8a8282f7
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sat May 16 15:34:31 2020 +0200
Add a Bash completion file
etc/bash_completion | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
etc/meson.build | 22 ++++++++++++++++
2 files changed, 98 insertions(+)
---
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 b3b20717ea..ded7a3f90d 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]