2019-01-03 20:35:51 +03:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2019-08-22 17:28:39 +03:00
|
|
|
# Description: Fuzzy find a file in directory subtree with fzy
|
|
|
|
# Opens in $VISUAL or $EDITOR if text
|
|
|
|
# Opens other type of files with xdg-open
|
2019-01-03 20:35:51 +03:00
|
|
|
#
|
2019-12-09 16:06:48 +03:00
|
|
|
# Requires: fzf/fzy, xdg-open
|
|
|
|
#
|
2019-03-24 18:41:43 +03:00
|
|
|
# Shell: POSIX compliant
|
2019-01-03 20:35:51 +03:00
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
2019-12-09 16:06:48 +03:00
|
|
|
if which fzf >/dev/null 2>&1; then
|
|
|
|
fuzzy=fzf
|
|
|
|
elif which fzy >/dev/null 2>&1; then
|
|
|
|
fuzzy=fzy
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
entry="$(find . -type f 2>/dev/null | "$fuzzy")"
|
2019-08-22 17:28:39 +03:00
|
|
|
|
|
|
|
case "$(file -biL "$entry")" in
|
|
|
|
*text*)
|
|
|
|
"${VISUAL:-$EDITOR}" "$entry" ;;
|
|
|
|
*)
|
|
|
|
xdg-open "$entry" >/dev/null 2>&1 ;;
|
|
|
|
esac
|