aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/eds.bash
blob: 0395fd4cdd8fd0c2a3c3c9eeb493307091835b35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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
    while IFS= read -rd '' executable ; do
        COMPREPLY[${#COMPREPLY[@]}]=$executable
    done < <(
        shopt -s dotglob nullglob
        declare -a files
        files=("${EDSPATH:-"$HOME"/.local/bin}"/"${COMP_WORDS[COMP_CWORD]}"*)
        declare -a executables
        for file in "${files[@]}" ; do
            [[ -f $file && -x $file ]] || continue
            executables[${#executables[@]}]=${file##*/}
        done
        ((${#executables[@]})) || exit 1
        printf '%q\0' "${executables[@]}"
    )
}
complete -F _eds eds