2019-10-23 13:04:12 +03:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-05-06 18:41:01 +05:30
|
|
|
# Description: Run fzf 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
|
|
|
|
2020-05-06 18:41:01 +05:30
|
|
|
if [ "$(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
|
2021-03-14 12:59:24 +05:30
|
|
|
if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then
|
2019-12-09 23:27:10 +05:30
|
|
|
exit 0
|
2021-03-14 12:19:40 +05:30
|
|
|
fi
|
2019-11-20 18:47:26 +05:30
|
|
|
|
2020-07-21 09:57:56 +02:00
|
|
|
# Check if selected path returned
|
|
|
|
# by fzf command is absolute
|
|
|
|
case $sel in
|
|
|
|
/*) nnn_cd "$sel" ;;
|
2020-11-22 20:54:49 +05:30
|
|
|
*)
|
2020-07-21 09:57:56 +02:00
|
|
|
# Remove "./" prefix if it exists
|
|
|
|
sel="${sel#./}"
|
2020-11-22 20:54:49 +05:30
|
|
|
|
2020-07-21 09:57:56 +02:00
|
|
|
if [ "$PWD" = "/" ]; then
|
|
|
|
nnn_cd "/$sel"
|
|
|
|
else
|
|
|
|
nnn_cd "$PWD/$sel"
|
|
|
|
fi;;
|
2020-11-22 20:54:49 +05:30
|
|
|
esac
|
2019-10-23 13:04:12 +03:00
|
|
|
fi
|