aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/eds.bash
blob: 1c5b2aa299c29527a3545f10f3d745f2004c816e (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
37
38
# Complete args to eds(1df) with existing executables in $EDSPATH, defaulting
# to ~/.local/bin
_eds() {
    local edspath
    edspath=${EDSPATH:-"$HOME"/.local/bin}
    [[ -d $edspath ]] || return
    local executable
    while IFS= read -rd '' executable ; do
        [[ -n $executable ]] || continue
        COMPREPLY[${#COMPREPLY[@]}]=$executable
    done < <(
        shopt -s dotglob nullglob

        # Make globbing case-insensitive if appropriate
        while read -r _ setting ; do
            case $setting in
                ('completion-ignore-case on')
                    shopt -s nocaseglob
                    break
                    ;;
            esac
        done < <(bind -v)

        declare -a files
        files=("${EDSPATH:-"$HOME"/.local/bin}"/"${COMP_WORDS[COMP_CWORD]}"*)
        declare -a executables
        for file in "${files[@]}" ; do
            ! [[ -d $file ]] || continue
            [[ -e $file ]] || continue
            [[ -x $file ]] || continue
            executables[${#executables[@]}]=${file##*/}
        done

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