Skip to content

cd completion lists all files, not just directories #13

Description

@PlasmaHH

With "plain" bash completion, the candidates are filtered by being a directory, however this extension also displays files (in an empty directory the behaviour differs too btw.).

I have been playing myself with getting a zsh like fuzzy completion and came up with the following based on fzf (which is far too fuzzy). The goal is to have a/b/e expand to alice/bob/eve/ ... maybe you can draw some ideas from it. The main way to filter for directories here is using ls -d ${pattern}/ ... the / at the end causes ls to "filter" for directories only, the -d causes ls to show the directory instead of its contents.

_XD( )
{
        cur=${COMP_WORDS[COMP_CWORD]}
        ARGNUM="${#COMP_WORDS[@]}"

        COMPREPLY=()

        PAT=$cur
        #set -x
        declare -a PREFIX=( "./" )
        while read COMP;
        do
                NEWPREFIXES=( )

                for PRE in "${PREFIX[@]}";
                do
                PRE=${PRE#./}
                MATCHES=$( ls -d ${PRE}*/ 2>/dev/null | fzf -f "${PRE}${COMP}")
                NEWPREFIXES=( ${NEWPREFIXES[@]} ${MATCHES} )
                done

                PREFIX=( ${NEWPREFIXES[@]} )
        done < <(echo $PAT | sed 's/\//\n/g')

        COMPREPLY=( ${NEWPREFIXES[@]} )

        return 0
}


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions