From e95d0a61bdbd3f0ace8e43d0bbab5b6a8b50c0df Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Thu, 4 Apr 2024 17:15:13 +0100 Subject: [PATCH] Command line auto-completion enhancements - Limit completions to a list of file extensions known to Geeqie - Limit completions to a specific extension where possible e.g. gqv - Change option +t to -T and +w to -w. The plus character affected the output of _parse_help - Additional warning to user for invalid parameters - unknown option or valid remote option used without a --remote command - New remote.cc function for above feature - Update man page and documentation --- auto-complete/geeqie | 56 +++++++++++++++++++++++++----- doc/docbook/CommandLineOptions.xml | 20 +++++------ geeqie.1 | 18 +++++----- src/main.cc | 13 ++++--- src/remote.cc | 15 ++++++-- src/remote.h | 2 +- 6 files changed, 86 insertions(+), 38 deletions(-) diff --git a/auto-complete/geeqie b/auto-complete/geeqie index 44b6a45b..ad59fceb 100755 --- a/auto-complete/geeqie +++ b/auto-complete/geeqie @@ -1,16 +1,56 @@ # bash completion for geeqie -*- shell-script -*- +file_types='@(3fr|ani|arw|avif|bmp|cr2|cr3|crw|cur|dds|djvu|dng|erf|gif|heic|heif|ico|jp2|jpe[g]||jpegxl|jps|kdc|mef|mos|mpo|mrw|nef|orf|pbm|pdf|pgm|pnm|ppm|pef|png|psd|qif|qtif|raf|raw|rw2|scr|sr2|srf|svg[z]|tga|targa|tif[f]|webp|xbm|xpm|gqv|xml|xmp)' + _geeqie() { - local cur - _init_completion -s || return + local cur prev + _init_completion -s || return + + case $prev in + :) + case ${COMP_WORDS[1]} in + --cache-render | --cache-render-recurse | --cache-render-shared-recurse | --get-filelist | --get-filelist-recurse | --slideshow-recurse) + compopt -o nospace + _filedir -d + return + ;; + --config-load) + compopt -o nospace + _filedir xml + return + ;; + --file | --File | --get-destination | --get-sidecars | --list-add | --selection-add | --selection-remove | --view) + compopt -o nospace + _filedir $file_types + return + ;; + --get-collection) + compopt -o nospace + _filedir gqv + return + ;; + --lua) + compopt -o nospace + _filedir lua + return + ;; + esac + ;; + --cache-maintenance) + _filedir -d + return + ;; + esac + + if [[ $cur == -* ]] + then + COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + [[ ${COMPREPLY-} == *[=:] ]] && compopt -o nospace + return + fi - if [[ $cur == -* ]] - then - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) - [[ ${COMPREPLY-} == *= ]] && compopt -o nospace - return - fi +_filedir $file_types } && complete -F _geeqie geeqie diff --git a/doc/docbook/CommandLineOptions.xml b/doc/docbook/CommandLineOptions.xml index 63c253c9..91286d6c 100644 --- a/doc/docbook/CommandLineOptions.xml +++ b/doc/docbook/CommandLineOptions.xml @@ -7,8 +7,8 @@ GEEQIE 1 -March 2024 -Geeqie 2.4 GTK3 +April 2024 +Geeqie 2.4+git20240402-d802d5f5 GTK3 Geeqie @@ -30,7 +30,7 @@ zooming, panning, thumbnails and sorting images into collections. Generated for version: -Geeqie 2.4 +Geeqie 2.4+git20240402-d802d5f5 Valid options: @@ -105,7 +105,7 @@ zooming, panning, thumbnails and sorting images into collections. - +t, --with-tools + -T, --with-tools force show of tools @@ -123,7 +123,7 @@ zooming, panning, thumbnails and sorting images into collections. - +w, --show-log-window + -w, --show-log-window show log window @@ -212,15 +212,15 @@ can be used to modify this behavior on an individual basis e.g. - -cs: --cache-shared:clear|clean + -cs: --cache-shared:clean|clear -clear or clean shared thumbnail cache +clean or clear shared thumbnail cache - -ct: --cache-thumbs:clear|clean + -ct: --cache-thumbs:clean|clear -clear or clean thumbnail cache +clean or clear thumbnail cache @@ -458,7 +458,7 @@ can be used to modify this behavior on an individual basis e.g. - +t --tools-show + -T --tools-show show tools diff --git a/geeqie.1 b/geeqie.1 index a17db0db..071730a1 100644 --- a/geeqie.1 +++ b/geeqie.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3. -.TH GEEQIE "1" "March 2024" "Geeqie 2.4 GTK3" "User Commands" +.TH GEEQIE "1" "April 2024" "Geeqie 2.4+git20240402-d802d5f5 GTK3" "User Commands" .SH NAME Geeqie - GTK based multiformat image viewer .SH SYNOPSIS @@ -11,7 +11,7 @@ zooming, panning, thumbnails and sorting images into collections. Generated for version: .PP -Geeqie 2.4 +Geeqie 2.4+git20240402\-d802d5f5 .SS "Valid options:" .TP \fB\-\-blank\fR @@ -49,7 +49,7 @@ print remote command list \fB\-s\fR, \fB\-\-slideshow\fR start in slideshow mode .TP -+t, \fB\-\-with\-tools\fR +\fB\-T\fR, \fB\-\-with\-tools\fR force show of tools .TP \fB\-t\fR, \fB\-\-without\-tools\fR @@ -58,7 +58,7 @@ force hide of tools \fB\-v\fR, \fB\-\-version\fR print version info .TP -+w, \fB\-\-show\-log\-window\fR +\fB\-w\fR, \fB\-\-show\-log\-window\fR show log window .TP \fB\-\-debug\fR[=\fI\,level\/\fR] @@ -104,11 +104,11 @@ render thumbnails (see Help) \fB\-crsr\fR: \fB\-\-cache\-render\-shared\-recurse\fR: render thumbnails recursively (see Help) .TP -\fB\-cs\fR: \fB\-\-cache\-shared\fR:clear|clean -clear or clean shared thumbnail cache +\fB\-cs\fR: \fB\-\-cache\-shared\fR:clean|clear +clean or clear shared thumbnail cache .TP -\fB\-ct\fR: \fB\-\-cache\-thumbs\fR:clear|clean -clear or clean thumbnail cache +\fB\-ct\fR: \fB\-\-cache\-thumbs\fR:clean|clear +clean or clear thumbnail cache .TP \fB\-d\fR \fB\-\-delay=\fR<[H:][M:][N][.M]> set slide show delay to Hrs Mins N.M seconds @@ -227,7 +227,7 @@ stop slide show \fB\-\-tell\fR print filename [and Collection] of current image .TP -+t \fB\-\-tools\-show\fR +\fB\-T\fR \fB\-\-tools\-show\fR show tools .TP \fB\-t\fR \fB\-\-tools\-hide\fR diff --git a/src/main.cc b/src/main.cc index b99f7d11..a12b5e4b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -436,12 +436,12 @@ static void parse_command_line(gint argc, gchar *argv[]) { /* do nothing but do not produce warnings */ } - else if (strcmp(cmd_line, "+t") == 0 || + else if (strcmp(cmd_line, "-T") == 0 || strcmp(cmd_line, "--with-tools") == 0) { command_line->tools_show = TRUE; - remote_list = g_list_append(remote_list, g_strdup("+t")); + remote_list = g_list_append(remote_list, g_strdup("-T")); } else if (strcmp(cmd_line, "-t") == 0 || strcmp(cmd_line, "--without-tools") == 0) @@ -478,7 +478,7 @@ static void parse_command_line(gint argc, gchar *argv[]) remote_list = remote_build_list(remote_list, argc - i, &argv[i], &remote_errors); } } - else if ((strcmp(cmd_line, "+w") == 0) || + else if ((strcmp(cmd_line, "-w") == 0) || strcmp(cmd_line, "--show-log-window") == 0) { command_line->log_window_show = TRUE; @@ -541,10 +541,10 @@ static void parse_command_line(gint argc, gchar *argv[]) print_term(FALSE, _(" -r, --remote send following commands to open window\n")); print_term(FALSE, _(" -rh, --remote-help print remote command list\n")); print_term(FALSE, _(" -s, --slideshow start in slideshow mode\n")); - print_term(FALSE, _(" +t, --with-tools force show of tools\n")); + print_term(FALSE, _(" -T, --with-tools force show of tools\n")); print_term(FALSE, _(" -t, --without-tools force hide of tools\n")); print_term(FALSE, _(" -v, --version print version info\n")); - print_term(FALSE, _(" +w, --show-log-window show log window\n")); + print_term(FALSE, _(" -w, --show-log-window show log window\n")); #ifdef DEBUG print_term(FALSE, _(" --debug[=level] turn on debug output\n")); print_term(FALSE, _(" -g:, --grep: filter debug output\n")); @@ -560,8 +560,7 @@ static void parse_command_line(gint argc, gchar *argv[]) } else if (!remote_do) { - command_line_errors = g_string_append(command_line_errors, cmd_line); - command_line_errors = g_string_append(command_line_errors, "\n"); + g_string_append_printf(command_line_errors, is_remote_command(cmd_line) ? _("%s\n\nThis is a --remote command option\n") : _("%s\n\nThis option is unknown\n"), cmd_line); } g_free(cmd_all); diff --git a/src/remote.cc b/src/remote.cc index e1102fd5..e6e6de74 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -1729,8 +1729,8 @@ static RemoteCommandEntry remote_commands[] = { { "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_(" "), N_("render thumbnails recursively") }, { "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_(" "), N_(" render thumbnails (see Help)") }, { "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_(""), N_(" render thumbnails recursively (see Help)") }, - { "-cs:", "--cache-shared:", gr_cache_shared, TRUE, FALSE, N_("clear|clean"), N_("clear or clean shared thumbnail cache") }, - { "-ct:", "--cache-thumbs:", gr_cache_thumb, TRUE, FALSE, N_("clear|clean"), N_("clear or clean thumbnail cache") }, + { "-cs:", "--cache-shared:", gr_cache_shared, TRUE, FALSE, N_("clean|clear"), N_("clean or clear shared thumbnail cache") }, + { "-ct:", "--cache-thumbs:", gr_cache_thumb, TRUE, FALSE, N_("clean|clear"), N_("clean or clear thumbnail cache") }, { "-d", "--delay=", gr_slideshow_delay, TRUE, FALSE, N_("<[H:][M:][N][.M]>"), N_("set slide show delay to Hrs Mins N.M seconds") }, { nullptr, "--first", gr_image_first, FALSE, FALSE, nullptr, N_("first image") }, { "-f", "--fullscreen", gr_fullscreen_toggle, FALSE, TRUE, nullptr, N_("toggle full screen") }, @@ -1775,7 +1775,7 @@ static RemoteCommandEntry remote_commands[] = { { "-ss","--slideshow-start", gr_slideshow_start, FALSE, FALSE, nullptr, N_("start slide show") }, { "-sS","--slideshow-stop", gr_slideshow_stop, FALSE, FALSE, nullptr, N_("stop slide show") }, { nullptr, "--tell", gr_file_tell, FALSE, FALSE, nullptr, N_("print filename [and Collection] of current image") }, - { "+t", "--tools-show", gr_tools_show, FALSE, TRUE, nullptr, N_("show tools") }, + { "-T", "--tools-show", gr_tools_show, FALSE, TRUE, nullptr, N_("show tools") }, { "-t", "--tools-hide", gr_tools_hide, FALSE, TRUE, nullptr, N_("hide tools") }, { nullptr, "--view:", gr_file_view, TRUE, FALSE, N_(""), N_("open FILE in new window") }, { nullptr, "view:", gr_file_view, TRUE, FALSE, N_(""), N_("open FILE in new window") }, @@ -1822,6 +1822,15 @@ static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar ** return nullptr; } +gboolean is_remote_command(const gchar *text) +{ + RemoteCommandEntry *entry = nullptr; + + entry = remote_command_find(text, nullptr); + + return entry ? TRUE : FALSE; +} + static void remote_cb(RemoteConnection *, const gchar *text, GIOChannel *channel, gpointer data) { RemoteCommandEntry *entry; diff --git a/src/remote.h b/src/remote.h index eb0f6f26..4b40a6b2 100644 --- a/src/remote.h +++ b/src/remote.h @@ -49,7 +49,7 @@ void remote_control(const gchar *arg_exec, GList *remote_list, const gchar *path RemoteConnection *remote_server_init(gchar *path, CollectionData *command_collection); gboolean remote_server_exists(const gchar *path); - +gboolean is_remote_command(const gchar *text); #endif /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ -- 2.20.1