From 28fe956a8e56c1d6b239cb76c248456cfb78aade Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Fri, 14 Oct 2022 11:35:31 +0200 Subject: [PATCH] - added first draft for bash completion, needs more work! --- test_complete.sh | 33 +++++++++++++++++++++++++++++++++ validate_workflow.sh | 12 +++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test_complete.sh diff --git a/test_complete.sh b/test_complete.sh new file mode 100644 index 0000000..235857e --- /dev/null +++ b/test_complete.sh @@ -0,0 +1,33 @@ +SELF=./validate_workflow.sh +_validate_workflow_completion() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts=$(cat $SELF | grep "^#hh\s-., --[a-z]" | sed -e "s/^#hh.*\(-.\), \(--[a-z-]*\).*/\1 \2/g") + 2>&1 echo "OPTS:$opts" + case "$prev" in + --pipe) + prev=$(echo $prev | sed -e "s/--\(daemon\|watch-folder\|result_folder\|valid_folder\|invalid_folder\)//g") + return 0 + ;; + --mode) + COMPREPLY=( $(compgen -W "auto mediathek fotothek save kitodo lfulg" -- ${cur}) ) + return 0 + ;; + --files-mode) + COMPREPLY=( $(compgen -W "nothing sort delete" -- ${cur}) ) + return 0 + ;; + -reset_failed_preingest|--reset_failed_preingest) + _pushd /mnt/import + _filedir -d + _popd + return + ;; + esac + # debug + 2>&1 echo "PREVS:$prevs" +} +complete -F _validate_workflow_completion validate_workflow.sh + diff --git a/validate_workflow.sh b/validate_workflow.sh index 6b2b5e6..51d7feb 100755 --- a/validate_workflow.sh +++ b/validate_workflow.sh @@ -54,7 +54,9 @@ #hh -p, --pipe #hh validates a single filestream from STDIN, writes result to STDOUT #hh no daemon, no folder nor filemode params needed -#hh +#hh -G, --gen-bash-complete +#hh prints a script for bash autocompletion, should be copied +#hh to /etc/bash_completion.d/validate_workflow #hh # expected programs: @@ -171,6 +173,14 @@ get_cli_args() { comment_help exit 0 ;; + -G | --gen_bash_complete) + + cat <<COMPLETE + + complete -F _validate_workflow_completion $(basename "${0}") +COMPLETE + exit 0 + ;; -D | --debug) WITH_DEBUG=1 shift -- GitLab