Skip to content

Commit

Permalink
feat(binaries): optimize directory search through fd and rg
Browse files Browse the repository at this point in the history
  • Loading branch information
spywhere committed Dec 19, 2024
1 parent 5fbb10e commit 432e09e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 17 additions & 7 deletions binaries/navigate
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ elif test -n "$@"; then
query="-q $*"
fi

bfs() {
for i in $(seq 1 5); do
find . -type d -mindepth "$i" -maxdepth "$i" -not -name .
done
find . -type d -mindepth 5 -not -name .
}
if test -n "$(command -v fd)"; then
bfs() {
fd --type d --exclude .git --exclude node_modules .
}
elif test -n "$(command -v rg)"; then
bfs() {
rg --files --iglob '!.git/**' --iglob '!node_modules/**' --null . | xargs -0 dirname | sort -u | cut -d'/' -f2-
}
else
bfs() {
for i in $(seq 1 5); do
find . -type d -mindepth "$i" -maxdepth "$i" -not -path '*/.*' -not -path '*/.git/*' -not -path '*/node_modules/*' | cut -d'/' -f2-
done
find . -type d -mindepth 5 -not -path '*/.*' -not -path '*/.git/*' -not -path '*/node_modules/*' | cut -d'/' -f2-
}
fi

"$command" "$(bfs | cut -d'/' -f2- | fzf --height=20 '--preview=ls -1 {}' '--bind=ctrl-/:toggle-preview' "$query")" || exit
"$command" "$(bfs | fzf --height=20 '--preview=ls -1 {}' '--bind=ctrl-/:toggle-preview' "$query")" || exit
12 changes: 11 additions & 1 deletion binaries/work
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ elif test -n "$@"; then
query="--query=$*"
fi

output="$(find "$WORKSPACE" -mindepth 1 -maxdepth 3 -type d -name '.git' | rev | cut -d'/' -f2- | rev | fzf --height=20 --print-query '--preview=git -C {} branch' '--bind=ctrl-/:toggle-preview' "$query")"
if test -n "$(command -v fd)"; then
search() {
fd --type d --max-depth 3 --no-ignore --hidden '\.git$' "$WORKSPACE" | rev | cut -d'/' -f3-
}
else
search() {
find "$WORKSPACE" -mindepth 1 -maxdepth 3 -type d -name '.git' | rev | cut -d'/' -f2-
}
fi

output="$(search | rev | fzf --height=20 --print-query '--preview=git -C {} branch' '--bind=ctrl-/:toggle-preview' "$query")"
query="$(echo "$output" | sed -n 1p)"
selection="$(echo "$output" | sed -n 2p)"
if test -n "$selection"; then
Expand Down

0 comments on commit 432e09e

Please sign in to comment.