From c8611edacb1911ef6a3ff2985387aefb8d98b59a Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Tue, 8 Oct 2024 19:01:07 -0700 Subject: [PATCH] client/container: src: completion: `plugins` enhancements - Re-enables space after completion for plugin arguments - Ignores internal/implementation files when completing * Files must be within an 'internal'/'impl' directory --- client/src/docker/completion.bash | 8 ++++++-- container/src/finance/completion.bash | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/docker/completion.bash b/client/src/docker/completion.bash index 100e1ee..c77c724 100644 --- a/client/src/docker/completion.bash +++ b/client/src/docker/completion.bash @@ -101,6 +101,9 @@ function docker-finance::completion() mapfile -t _reply < <(compgen -W "help gen${global_arg_delim_2} rm${global_arg_delim_2}" -- "$_cur") ;; plugins) + # Re-enable space after completion (for plugin args) + compopt +o nospace + # TODO: HACK: since this is completion, lib_docker is never initialized, prior to completing # (environment variables are needed). if [ -z "$DOCKER_FINANCE_CLIENT_REPO" ]; then @@ -117,10 +120,11 @@ function docker-finance::completion() fi [ -z "$DOCKER_FINANCE_CLIENT_PLUGINS" ] && lib_utils::print_fatal "DOCKER_FINANCE_CLIENT_PLUGINS not set" + local -r _args=("-type" "f" "-executable" "-not" "-path" "*/internal/*" "-not" "-path" "*/impl/*") local _plugins mapfile -t _plugins < <({ - find "${DOCKER_FINANCE_CLIENT_PLUGINS}"/client/docker -type f -executable -printf 'custom/%P\n' 2>/dev/null - find "${DOCKER_FINANCE_CLIENT_REPO}"/client/plugins/docker -type f -executable -printf 'repo/%P\n' 2>/dev/null + find "${DOCKER_FINANCE_CLIENT_PLUGINS}"/client/docker "${_args[@]}" -printf 'custom/%P\n' 2>/dev/null + find "${DOCKER_FINANCE_CLIENT_REPO}"/client/plugins/docker "${_args[@]}" -printf 'repo/%P\n' 2>/dev/null }) declare -r _plugins mapfile -t _reply < <(compgen -W "${_plugins[*]}" -- "$_cur") diff --git a/container/src/finance/completion.bash b/container/src/finance/completion.bash index e1ec34a..2a769be 100644 --- a/container/src/finance/completion.bash +++ b/container/src/finance/completion.bash @@ -109,13 +109,17 @@ function docker-finance::completion() mapfile -t _reply < <(compgen -W "help" -- "$_cur") ;; plugins) + # Re-enable space after completion (for plugin args) + compopt +o nospace + [ -z "$DOCKER_FINANCE_CONTAINER_REPO" ] && lib_utils::die_fatal [ -z "$DOCKER_FINANCE_CONTAINER_PLUGINS" ] && lib_utils::die_fatal + local -r _args=("-type" "f" "-executable" "-not" "-path" "*/internal/*" "-not" "-path" "*/impl/*") local _plugins mapfile -t _plugins < <({ - find "${DOCKER_FINANCE_CONTAINER_PLUGINS}"/finance -type f -executable -printf 'custom/%P\n' 2>/dev/null - find "${DOCKER_FINANCE_CONTAINER_REPO}"/plugins/finance -type f -executable -printf 'repo/%P\n' 2>/dev/null + find "${DOCKER_FINANCE_CONTAINER_PLUGINS}"/finance "${_args[@]}" -printf 'custom/%P\n' 2>/dev/null + find "${DOCKER_FINANCE_CONTAINER_REPO}"/plugins/finance "${_args[@]}" -printf 'repo/%P\n' 2>/dev/null }) declare -r _plugins mapfile -t _reply < <(compgen -W "${_plugins[*]}" -- "$_cur")