2021-07-06 22:48:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Quick directory switcher based on zoxide and fzf
|
|
|
|
if test -d "$1" -o "$1" = "-"
|
|
|
|
then echo "$@"
|
|
|
|
else
|
|
|
|
set -o noglob
|
|
|
|
query=$(zoxide query -sl "$@")
|
|
|
|
# First find out whether there is an obvious match (score at least ten times that of runner-up)
|
|
|
|
# If not select with fzf, using locate to find extra options
|
2021-07-10 19:47:54 +00:00
|
|
|
( expr $(echo "$query" | sed 'N;s|/.*\n|> 10 *|;q' | sed 's| */.*||') >/dev/null 2>&1 &&
|
2021-07-06 22:48:35 +00:00
|
|
|
echo "$query" | head -1 ||
|
|
|
|
( echo "$query"; locate --basename --existing "$@" | while read -r file; do test -d "$file" && echo "$file"; done | sed 's/^/ 0 /' ) |
|
|
|
|
fzf -0 -1 -n2.. --tiebreak=index --preview="ls -a --color --human-readable --group-directories-first --file-type {2..}" --preview-window=20% ) | tr -s ' ' | cut -d' ' -f3-
|
|
|
|
fi
|