mirror of
https://github.com/jarun/nnn.git
synced 2024-11-16 08:03:16 +00:00
36 lines
681 B
Bash
Executable file
36 lines
681 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=$(fzf)
|
|
else
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "$sel" ]; then
|
|
if [ "$sel" = "." ] || { ! [ -d "$sel" ] && ! [ -f "$sel" ]; }; then
|
|
exit 0
|
|
fi
|
|
|
|
# Check if selected path returned
|
|
# by fzf command is absolute
|
|
case $sel in
|
|
/*) nnn_cd "$sel" ;;
|
|
*)
|
|
# Remove "./" prefix if it exists
|
|
sel="${sel#./}"
|
|
|
|
if [ "$PWD" = "/" ]; then
|
|
nnn_cd "/$sel"
|
|
else
|
|
nnn_cd "$PWD/$sel"
|
|
fi;;
|
|
esac
|
|
fi
|