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