aboutsummaryrefslogblamecommitdiff
path: root/bash/bash_completion.d/find.bash
blob: 893cb0bc7cc767b73f2102b84ac86bb0a05dfbac (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                            



                                                      

             
                                          
                  
                



















                            
                         
                    


                  
                                                                  
                  
                  

                                                           
                                                          

                                         



                                                         

                                                     

                                              


            
                                                
# Semi-intelligent completion for find(1); nothing too crazy
_find() {

    # Iterate through completions produced by subshell
    local ci comp
    while IFS= read -r comp ; do
        COMPREPLY[ci++]=$comp
    done < <(

        # Complete POSIX-specified options
        case $2 in
            (-*)
                compgen -W '
                    -atime
                    -ctime
                    -depth
                    -exec
                    -group
                    -links
                    -mtime
                    -name
                    -newer
                    -nogroup
                    -nouser
                    -ok
                    -perm
                    -print
                    -prune
                    -size
                    -type
                    -user
                    -xdev
                ' -- "$2"
                exit
                ;;
        esac

        # Look at the word *before* this one to figure out what to
        # complete
        case $3 in

            # Args to -exec and -execdir should be commands
            (-exec|-execdir) compgen -A command -- "$2" ;;

            # Legal POSIX flags for -type
            (-type) compgen -W 'b c d f l p s' -- "$2" ;;

            # Args to -group should complete group names
            (-group) compgen -A group -- "$2" ;;

            # Args to -user should complete usernames
            (-user) compgen -A user -- "$2" ;;

        esac
    )
}
complete -F _find -o bashdefault -o default find