From 809d465de5da8c29508b6839127f0098e821fc97 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 2 May 2014 12:52:06 +0900 Subject: [PATCH] Tip on using git ls-tree (#31) --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index e47b26f..03a2c49 100644 --- a/README.md +++ b/README.md @@ -458,6 +458,26 @@ export FZF_DEFAULT_COMMAND='ag -l -g ""' fzf ``` +### `git ls-tree` for fast traversal + +If you're running fzf in a large git repository, `git ls-tree` can boost up the +speed of the traversal. + +```sh +# Copy the original fzf function to __fzf +declare -f __fzf > /dev/null || + eval "$(echo "__fzf() {"; declare -f fzf | grep -v '^{' | tail -n +2)" + +# Use git ls-tree when possible +fzf() { + if [ -n "$(git rev-parse HEAD 2> /dev/null)" ]; then + FZF_DEFAULT_COMMAND="git ls-tree -r --name-only HEAD" __fzf "$@" + else + __fzf "$@" + fi +} +``` + ### Fish shell It's [a known bug of fish](https://github.com/fish-shell/fish-shell/issues/1362)