diff --git a/test_complete.sh b/test_complete.sh new file mode 100644 index 0000000000000000000000000000000000000000..235857eb8d73e5deae82a76e299e1fb502ecf9bd --- /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 6b2b5e6227f28d3fcfd8c95f2b37bc78f88416a3..51d7feb1ebf37298748e61bcf075039a36dcacfb 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