nnn/plugins/fzcd

37 lines
661 B
Plaintext
Raw Normal View History

#!/usr/bin/env sh
2019-12-09 13:06:48 +00:00
# Description: Run fzf/fzy, fd/fdfind/find and go to the directory of the file selected
#
# Shell: POSIX compliant
# Author: Anna Arad
2019-11-21 20:44:25 +00:00
. "$(dirname "$0")"/.nnn-plugin-helper
if [ "$(cmd_exists fzy)" -eq "0" ]; then
if [ "$(cmd_exists fd)" -eq "0" ]; then
fd=fd
elif [ "$(cmd_exists fdfind)" -eq "0" ]; then
fd=fdfind
else
fd=find
fi
sel=$($fd | fzy)
elif [ "$(cmd_exists fzf)" -eq "0" ]; then
sel=$(fzf)
else
exit 1
fi
if [ -n "$sel" ]; then
if ! [ -d "$sel" ]; then
sel=$(dirname "$sel")
2019-12-09 17:57:10 +00:00
elif [ "$sel" = "." ]; then
exit 0
fi
# Remove "./" prefix if it exists
sel="${sel#./}"
nnn_cd "$PWD/$sel"
fi