scripts/dav-bash-completion.bash

Mon, 09 Aug 2021 17:22:21 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 09 Aug 2021 17:22:21 +0200
changeset 736
40be8db6fe45
parent 684
a4b4257c1a5f
permissions
-rw-r--r--

fix dav-sync push creating finfo elements without using the mempool, which could lead to crashes

dav_completion_build_args() {
    local word
    for i in "${!COMP_WORDS[@]}"; do
        word="${COMP_WORDS[$i]}"
        if [[ "$word" =~ ^\'|^\" ]]; then
            printf "%s\n" "$word"
        else
            echo "$word" | xargs printf "%s"
            printf "\n"
        fi
    done
}

dav_completion() {
    local cmd
    local out
    local cmd_res

    cmd="${COMP_WORDS[0]} complete $COMP_CWORD"
    out=$(dav_completion_build_args | $cmd 2> /dev/null)
    cmd_res=$?

    if [[ $cmd_res -eq 10 ]]; then
        compopt -o nospace
	fi
	
	
    if [[ $cmd_res -eq 12 ]]; then
        compopt -o default
        COMPREPLY=()
    else
        IFS=$'\n' declare -ga 'COMPREPLY=($out)'
    fi
}

complete -F dav_completion dav

mercurial