2019-10-23 10:04:12 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-05-06 13:11:01 +00:00
|
|
|
# Description: Run fzf 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
|
|
|
|
2020-05-06 13:11:01 +00:00
|
|
|
if [ "$(cmd_exists fzf)" -eq "0" ]; then
|
2019-11-26 12:36:31 +00:00
|
|
|
sel=$(fzf)
|
2021-05-28 13:34:14 +00:00
|
|
|
# Show only the file and parent dir
|
2021-04-17 13:55:07 +00:00
|
|
|
# sel=$(fzf --delimiter / --with-nth=-2,-1 --tiebreak=begin --info=hidden)
|
2019-10-23 10:04:12 +00:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-26 12:36:31 +00:00
|
|
|
if [ -n "$sel" ]; then
|
2021-03-14 07:29:24 +00:00
|
|
|
if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then
|
2019-12-09 17:57:10 +00:00
|
|
|
exit 0
|
2021-03-14 06:49:40 +00:00
|
|
|
fi
|
2019-11-20 13:17:26 +00:00
|
|
|
|
2020-07-21 07:57:56 +00:00
|
|
|
# Check if selected path returned
|
|
|
|
# by fzf command is absolute
|
|
|
|
case $sel in
|
|
|
|
/*) nnn_cd "$sel" ;;
|
2020-11-22 15:24:49 +00:00
|
|
|
*)
|
2020-07-21 07:57:56 +00:00
|
|
|
# Remove "./" prefix if it exists
|
|
|
|
sel="${sel#./}"
|
2020-11-22 15:24:49 +00:00
|
|
|
|
2020-07-21 07:57:56 +00:00
|
|
|
if [ "$PWD" = "/" ]; then
|
|
|
|
nnn_cd "/$sel"
|
|
|
|
else
|
|
|
|
nnn_cd "$PWD/$sel"
|
|
|
|
fi;;
|
2020-11-22 15:24:49 +00:00
|
|
|
esac
|
2019-10-23 10:04:12 +00:00
|
|
|
fi
|