💾 Archived View for gmn.clttr.info › sources › photo-stats.git › tree › phosta-completion.sh.txt captured on 2023-05-24 at 18:04:19.
-=-=-=-=-=-=-
#!/bin/bash # shellcheck disable=SC2207 _phosta_completions() { local cur=${COMP_WORDS[COMP_CWORD]} local prev=${COMP_WORDS[COMP_CWORD-1]} local prefix="" if [[ ${cur} =~ "," ]]; then prefix="${cur%,*}," fi local suggestions="" case "${prev}" in "-o") suggestions=($(compgen -W "${prefix}year ${prefix}month ${prefix}week ${prefix}hour ${prefix}file ${prefix}maker ${prefix}model ${prefix}lensmaker ${prefix}lens ${prefix}aperture ${prefix}exposuretime ${prefix}iso ${prefix}focallength ${prefix}focallength35mm" "${cur}")) ;; "-s") suggestions=($(compgen -W "${prefix}file ${prefix}maker ${prefix}model ${prefix}lensmaker ${prefix}lens ${prefix}aperture ${prefix}exposuretime ${prefix}iso ${prefix}focallength ${prefix}focallength35mm" "${cur}")) ;; "-g") suggestions=($(compgen -W "${prefix}year ${prefix}month ${prefix}week ${prefix}hour" "${cur}")) ;; "-T") suggestions=($(compgen -W "auto on off" "${cur}")) ;; "-n") suggestions=($(compgen -W "10 20 50 100" "${cur}")) ;; "-W") suggestions=($(compgen -W "80 100 120" "${cur}")) ;; "-t") if [ "${cur}" == "" ]; then suggestions=($(compgen -W "$(date +%Y)0101-$(date +%Y)1231")) else suggestions=($(compgen -W "${cur}0101-${cur}1231" "${cur}")) fi ;; "-p") suggestions=($(compgen -d "${cur}")) ;; "-D") suggestions=($(compgen -f "${cur}")) ;; esac if [ "${#suggestions[@]}" == "1" ]; then # if there's only one match, we remove the command literal # to proceed with the automatic completion of the command # shellcheck disable=SC2116 suggestion=$(echo "${suggestions[0]/%\ */}") COMPREPLY=("${suggestion}") else # more than one suggestions resolved, # respond with the suggestions intact COMPREPLY=("${suggestions[@]}") fi return 0 } complete -o nospace -F _phosta_completions phosta