aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/td.bash
blob: 92927c28ffb948b996f42cfbb1cf452c2da73e77 (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
27
28
29
30
31
32
33
34
35
36
# 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

        # Make globbing case-insensitive if appropriate; is there a cleaner way
        # to find this value?
        while read -r _ option value ; do
            case $option in
                (completion-ignore-case)
                    case $value in
                        (on)
                            shopt -s nocaseglob
                            break
                            ;;
                    esac
                    ;;
            esac
        done < <(bind -v)

        declare -a fns
        fns=("$dir"/"${COMP_WORDS[COMP_CWORD]}"*)
        fns=("${fns[@]#"$dir"/}")

        # Print quoted entries, null-delimited
        printf '%q\0' "${fns[@]}"
    )
}
complete -F _td td