Implement basic command line auto-completion
authorColin Clark <colin.clark@cclark.uk>
Mon, 1 Apr 2024 18:56:50 +0000 (19:56 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 1 Apr 2024 18:56:50 +0000 (19:56 +0100)
_parse_help is used to provide auto-completion for long options.
No other processing is done.

auto-complete/geeqie [new file with mode: 0755]
auto-complete/meson.build [new file with mode: 0644]
meson.build

diff --git a/auto-complete/geeqie b/auto-complete/geeqie
new file mode 100755 (executable)
index 0000000..4dd9b83
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+_geeqie()
+{
+    local cur
+    _init_completion -s || return
+
+    if [[ $cur == -* ]]
+    then
+        # shellcheck disable=SC2207
+        # shellcheck disable=SC2016
+        COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
+        [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
+        return
+    fi
+
+} &&
+    complete -F _geeqie geeqie
+
+# ex: filetype=sh
diff --git a/auto-complete/meson.build b/auto-complete/meson.build
new file mode 100644 (file)
index 0000000..19438d6
--- /dev/null
@@ -0,0 +1,14 @@
+# This file is a part of Geeqie project (https://www.geeqie.org/).
+# Copyright (C) 2008 - 2024 The Geeqie Team
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#
+
+install_data('geeqie', install_dir : completionsdir)
index 946e285..90ac63c 100644 (file)
@@ -34,6 +34,7 @@
 # [gq_]htmldir  /usr/local/share/doc/geeqie/html    *   help files
 # gq_localedir  /usr/locale/share/locale
 # mandir1       /usr/local/share/man/man1               man page
+# completionsdir /usr/local/share/bash-completion/completions bash command line completions
 # podir         project_root/po
 
 # * See meson_options.txt file
@@ -134,7 +135,7 @@ helpdir = join_paths(prefix, gq_helpdir)
 htmldir = join_paths(prefix, gq_htmldir)
 icondir = join_paths(datadir, 'pixmaps')
 mandir1 = join_paths(datadir, 'man', 'man1')
-
+completionsdir = join_paths(datadir, 'bash-completion', 'completions')
 podir = join_paths(meson.project_source_root(), 'po')
 scriptsdir = join_paths(meson.project_source_root(), 'scripts')
 
@@ -616,6 +617,9 @@ subdir('src')
 # Generate the help files
 subdir('doc')
 
+# Generate the command line auto-complete file
+subdir('auto-complete')
+
 # Install other project files
 if running_from_git
     cmd = [find_program('gen_changelog.sh'), meson.current_source_dir(), meson.current_build_dir()]