config/shell/browse/d: speed up and robustify

This commit is contained in:
xeruf 2022-06-27 22:58:12 +02:00
parent 3ba0316e7d
commit 7df7c08730
1 changed files with 5 additions and 4 deletions

View File

@ -81,8 +81,9 @@ zoxide-fzf() {
}
# Locate directories and add 0 zoxide score
locate-zox() {
locate --basename --ignore-case "$@" |
while read -r file; do test -d "$file" && echo "$file"; done |
locate --existing --basename --ignore-case "$@" |
# TODO too slow
# while read -r file; do test -d "$file" && echo "$file"; done |
sed 's/^/ 0 /'
}
# Switch directory heuristically using zoxide and locate
@ -94,12 +95,12 @@ d() {
# If not select with fzf, using locate to find extra options
target="$(if test -n "$query" &&
expr "$(echo "$query" | sed 's| \+\([^ ]\+\).*|\1|;q')" \> 20 \& \
$(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
$(echo "$query" | sed 'N;s|/.* \([0-9]\+\) */.*|> 10 * \1|;q') >/dev/null #2>&1
then echo "$query" | head -1
else test -n "$query" && echo "$query"; locate-zox "$@"
fi | zoxide-fzf)"
test $? -lt 2 && test -z "$target" && sudo updatedb && target="$(locate --basename "$@" | fzf-dir)"
test -n "$target" && cd "$target"
test -n "$target" && cde "$target"
}
# Switch directory interactively using zoxide and locate
di() {