mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
1afdd48f5d
* nuke: use macOS open when GUI enabled * nuke: use is_mac function to test for macOS This is consistent with how the imgur plugin does detection. * Add macOS open command to plugins * pskill: only execute if input is non-empty
39 lines
1.1 KiB
Bash
Executable file
39 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
# Description: Fuzzy find a file in directory subtree
|
|
# Opens in $VISUAL or $EDITOR if text
|
|
# Opens other type of files with xdg-open
|
|
#
|
|
# Dependencies: fd/find, fzf/skim, xdg-open
|
|
#
|
|
# Shell: POSIX compliant
|
|
# Author: Arun Prakash Jana
|
|
|
|
if which fzf >/dev/null 2>&1; then
|
|
cmd="$FZF_DEFAULT_COMMAND"
|
|
if which fd >/dev/null 2>&1; then
|
|
[ -z "$cmd" ] && cmd="fd -t f 2>/dev/null"
|
|
else
|
|
[ -z "$cmd" ] && cmd="find . -type f 2>/dev/null"
|
|
fi
|
|
entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
|
|
# To show only the file name
|
|
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
|
|
elif which sk >/dev/null 2>&1; then
|
|
entry=$(find . -type f 2>/dev/null | sk)
|
|
else
|
|
exit 1
|
|
fi
|
|
|
|
case "$(file -biL "$entry")" in
|
|
*text*)
|
|
"${VISUAL:-$EDITOR}" "$entry" ;;
|
|
*)
|
|
if uname | grep -q "Darwin"; then
|
|
open "$entry" >/dev/null 2>&1
|
|
else
|
|
xdg-open "$entry" >/dev/null 2>&1
|
|
fi
|
|
;;
|
|
esac
|