2019-10-23 10:04:12 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2019-12-08 20:27:31 +00:00
|
|
|
# Description: Run fzf/fzy/fd/fdfind/find and go to the directory of the file selected
|
2019-10-23 10:04:12 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Anna Arad
|
|
|
|
|
2019-11-21 20:44:25 +00:00
|
|
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
2019-10-23 10:04:12 +00:00
|
|
|
|
|
|
|
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
|
2019-11-26 12:36:31 +00:00
|
|
|
sel=$(fzf)
|
2019-10-23 10:04:12 +00:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-26 12:36:31 +00:00
|
|
|
if [ -n "$sel" ]; then
|
|
|
|
if ! [ -d "$sel" ]; then
|
|
|
|
sel=$(dirname "$sel")
|
|
|
|
fi
|
2019-11-20 13:17:26 +00:00
|
|
|
|
2019-11-26 12:36:31 +00:00
|
|
|
# Remove "./" prefix if it exists
|
|
|
|
sel="${sel#./}"
|
2019-10-23 10:04:12 +00:00
|
|
|
nnn_cd "$PWD/$sel"
|
|
|
|
fi
|