aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/td.bash
blob: eb29992b6a9c6cceefbcb96cfd1e4aec16796141 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Complete filenames for td(1df)
_td() {
    local dir
    dir=${TODO_DIR:-"$HOME"/Todo}
    local fn
    while IFS= read -rd '' fn ; do
        COMPREPLY[${#COMPREPLY[@]}]=$fn
    done < <(
        shopt -s extglob nullglob
        shopt -u dotglob
        local -a fns
        fns=("$dir"/"${COMP_WORDS[COMP_CWORD]}"*)
        fns=("${fns[@]#"$dir"/}")
        ((${#fns[@]})) || exit 1
        printf '%s\0' "${fns[@]##"$dir"/}"
    )
    return
}
complete -F _td td