Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"------------------------------------------------------------
" CtrlP
"------------------------------------------------------------
" Set the max files
let g:ctrlp_max_files = 10000
" Optimize file searching
if has("unix")
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git/', 'cd %s && git ls-files']
\ },
\ 'fallback': 'find %s -type f | head -' . g:ctrlp_max_files
\ }
endif
@hynek

This comment has been minimized.

Copy link

@hynek hynek commented May 1, 2012

JFTR, the Mercurial equivalent of git ls-files would be hg manifest – works like a charm too.

@shurane

This comment has been minimized.

Copy link

@shurane shurane commented May 3, 2012

You can probably make this a step better by caching the output of find, like:

FILELIST=filelist
if [[ ! =f $FILELIST ]]; then find . -type f > $FILELIST; fi

cat $FILELIST

Or something along those lines. I'm copying, more or less, code from build/envsetup.sh#godir() from Google's Android source, which is somewhat convenient in traversing 30000+ files:

function godir () {
    if [[ -z "$1" ]]; then
        echo "Usage: godir <regex>"
        return
    fi
    T=$(gettop)
    if [[ ! -f $T/filelist ]]; then
        echo -n "Creating index..."
        (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
        echo " Done"
        echo ""
    fi
    local lines
    lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
    if [[ ${#lines[@]} = 0 ]]; then
        echo "Not found"
        return
    fi
    local pathname
    local choice
    if [[ ${#lines[@]} > 1 ]]; then
        while [[ -z "$pathname" ]]; do
            local index=1
            local line
            for line in ${lines[@]}; do
                printf "%6s %s\n" "[$index]" $line
                index=$(($index + 1))
            done
            echo
            echo -n "Select one: "
            unset choice
            read choice
            if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
                echo "Invalid choice"
                continue
            fi
            pathname=${lines[$(($choice-1))]}
        done
    else
        pathname=${lines[0]}
    fi
    cd $T/$pathname
}
@mitchellh

This comment has been minimized.

Copy link
Owner Author

@mitchellh mitchellh commented May 3, 2012

@shurane Actually CtrlP handles caching for you! :)

@vsiegel

This comment has been minimized.

Copy link

@vsiegel vsiegel commented Mar 25, 2016

@shurane The uncached version kills the find process after reading "g:ctrlp_max_files" lines; The cached version writes all results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.