aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/td.bash
blob: db232dd6ca690088c68e0583ebb5c68282662ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Complete filenames for td(1df)
_td() {
    local dir
    dir=${TODO_DIR:-"$HOME"/Todo}
    local fn
    while IFS= read -rd '' fn ; do
        [[ -n $fn ]] || continue
        COMPREPLY[${#COMPREPLY[@]}]=$fn
    done < <(
        shopt -s extglob nullglob
        shopt -u dotglob
        declare -a fns
        fns=("$dir"/"${COMP_WORDS[COMP_CWORD]}"*)
        fns=("${fns[@]#"$dir"/}")

        # Print quoted entries, null-delimited, if there was at least one;
        # otherwise, just print a null character to stop this hanging in Bash
        # 4.4
        if ((${#fns[@]})) ; then
            printf '%q\0' "${fns[@]}"
        else
            printf '\0'
        fi
    )
}
complete -F _td td