nnn/plugins/fzcd

31 lines
521 B
Plaintext
Raw Normal View History

#!/usr/bin/env sh
2020-05-06 13:11:01 +00:00
# Description: Run fzf 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
2020-05-06 13:11:01 +00:00
if [ "$(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#./}"
2020-03-31 16:56:20 +00:00
if [ "$PWD" = "/" ]; then
nnn_cd "/$sel"
else
nnn_cd "$PWD/$sel"
fi
fi