helper-scripts/zsh/_fuzzy_cd
2019-03-01 16:23:18 -08:00

34 lines
556 B
Plaintext

#compdef fcd
# Fuzzy cd from anywhere
# Dependencies
# * fzf
# * mlocate
# ========== Shortcuts ==========
cf() {
[[ -z "${*}" ]] && return 1
[[ ! -x /usr/bin/fzf ]] && return 1
dir="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --select-1 --exit-0)"
[[ -z "${dir}" ]] && return 1
if [[ -f "${dir}" ]]; then
cd "${dir%/*}"
else
cd "${dir}"
fi
}
autoload -Uz cf
# ========== Completions ==========
local arguments
arguments=(
$argument_list
'*:filename:_files'
)
_arguments -s $arguments