aboutsummaryrefslogblamecommitdiff
path: root/bash/bashrc.d/vis.bash
blob: f84cb7024379ecfd0385d0dab0a19b7066d20c63 (plain) (tree)
1
2
3
4
5
6
7
8



                                                                              
                                          
                               
                                          
                                               


                                 
                                                                             

                                      
                                                  
                                                       





                                         
# Complete args to vis(1) with existing executables in $VISPATH, defaulting to
# ~/.local/bin
_vis() {
    local vispath
    vispath=${VISPATH:-"$HOME"/.local/bin}
    [[ -d $vispath ]] || return
    while IFS= read -rd '' executable ; do
        COMPREPLY[${#COMPREPLY[@]}]=$executable
    done < <(
        shopt -s dotglob nullglob
        declare -a files
        files=("${VISPATH:-"$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 _vis vis