2019-01-03 17:35:51 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2021-05-16 19:25:29 +00:00
|
|
|
# Description: Regular mode:
|
|
|
|
# Fuzzy find a file in directory subtree.
|
|
|
|
# Opens in $VISUAL or $EDITOR if text.
|
|
|
|
# Opens other type of files with xdg-open.
|
|
|
|
# Work only with a single file selected.
|
|
|
|
#
|
|
|
|
# Picker mode:
|
|
|
|
# If picker mode output file is passed, it
|
|
|
|
# will be overwritten with any picked files.
|
|
|
|
# Leaves untouched if no file is picked.
|
|
|
|
# Works with single/multiple files selected.
|
2019-01-03 17:35:51 +00:00
|
|
|
#
|
2020-05-06 13:11:01 +00:00
|
|
|
# Dependencies: fd/find, fzf/skim, xdg-open
|
2019-12-09 13:06:48 +00:00
|
|
|
#
|
2019-03-24 15:41:43 +00:00
|
|
|
# Shell: POSIX compliant
|
2019-01-03 17:35:51 +00:00
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
2021-05-16 19:25:29 +00:00
|
|
|
. "$(dirname "$0")"/.nnn-plugin-helper
|
|
|
|
|
2021-05-14 12:03:28 +00:00
|
|
|
if type fzf >/dev/null 2>&1; then
|
2020-04-12 13:36:59 +00:00
|
|
|
cmd="$FZF_DEFAULT_COMMAND"
|
2021-05-14 12:03:28 +00:00
|
|
|
if type fd >/dev/null 2>&1; then
|
2020-04-26 18:35:11 +00:00
|
|
|
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
|
|
|
|
else
|
|
|
|
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
|
|
|
|
fi
|
2021-05-16 19:25:29 +00:00
|
|
|
entry="$(eval "$cmd" | fzf -m --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
|
2020-02-20 03:07:49 +00:00
|
|
|
# To show only the file name
|
|
|
|
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type sk >/dev/null 2>&1; then
|
2020-04-20 17:09:30 +00:00
|
|
|
entry=$(find . -type f 2>/dev/null | sk)
|
2019-12-09 13:06:48 +00:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-05-16 19:25:29 +00:00
|
|
|
# Check for picker mode
|
|
|
|
if [ "$3" ]; then
|
|
|
|
if [ "$entry" ]; then
|
|
|
|
if [ "-" = "$3" ]; then
|
|
|
|
printf "%s\n" "$entry"
|
|
|
|
else
|
|
|
|
printf "%s\n" "$entry" > "$3"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Tell `nnn` to clear its internal selection
|
|
|
|
printf "%s" "0p" > "$NNN_PIPE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Open the file (works for a single file only)
|
2019-08-22 14:28:39 +00:00
|
|
|
case "$(file -biL "$entry")" in
|
|
|
|
*text*)
|
|
|
|
"${VISUAL:-$EDITOR}" "$entry" ;;
|
|
|
|
*)
|
2020-08-20 09:21:26 +00:00
|
|
|
if uname | grep -q "Darwin"; then
|
|
|
|
open "$entry" >/dev/null 2>&1
|
|
|
|
else
|
|
|
|
xdg-open "$entry" >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
;;
|
2019-08-22 14:28:39 +00:00
|
|
|
esac
|