FollieHiyuki-dotfiles/home/.config/nnn/plugins/fzcd
2021-02-13 19:28:59 +03:00

23 lines
510 B
Bash
Executable File

#!/usr/bin/env sh
# Description: Run fzf and go to the directory of the file selected
#
# Shell: POSIX compliant
# Author: Anna Arad
. "$(dirname "$0")"/.nnn-plugin-helper
if [ "$(cmd_exists fzf)" -eq "0" ]; then
sel=$(fd --type d --follow --hidden --exclude .git | fzf --preview 'tree -La 1 -C --dirsfirst {} 2>/dev/null')
else
exit 1
fi
if [ -n "$sel" ]; then
# Check if selected path returned by fzf command is absolute
case $sel in
/*) nnn_cd "$sel" ;;
*) nnn_cd "$PWD/$sel" ;;
esac
fi