2019-01-03 23:05:51 +05:30
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2020-05-06 18:41:01 +05:30
|
|
|
# Description: Fuzzy find a file in directory subtree
|
2019-08-22 19:58:39 +05:30
|
|
|
# Opens in $VISUAL or $EDITOR if text
|
|
|
|
# Opens other type of files with xdg-open
|
2019-01-03 23:05:51 +05:30
|
|
|
#
|
2020-05-06 18:41:01 +05:30
|
|
|
# Dependencies: fd/find, fzf/skim, xdg-open
|
2019-12-09 18:36:48 +05:30
|
|
|
#
|
2019-03-24 21:11:43 +05:30
|
|
|
# Shell: POSIX compliant
|
2019-01-03 23:05:51 +05:30
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
2019-12-09 18:36:48 +05:30
|
|
|
if which fzf >/dev/null 2>&1; then
|
2020-04-12 20:36:59 +07:00
|
|
|
cmd="$FZF_DEFAULT_COMMAND"
|
2020-04-27 00:05:11 +05:30
|
|
|
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
|
2020-04-12 20:36:59 +07:00
|
|
|
entry="$(eval "$cmd" | fzf --delimiter / --nth=-1 --tiebreak=begin --info=hidden)"
|
2020-02-20 08:37:49 +05:30
|
|
|
# To show only the file name
|
|
|
|
# entry=$(find . -type f 2>/dev/null | fzf --delimiter / --with-nth=-1 --tiebreak=begin --info=hidden)
|
2020-04-20 19:09:30 +02:00
|
|
|
elif which sk >/dev/null 2>&1; then
|
|
|
|
entry=$(find . -type f 2>/dev/null | sk)
|
2019-12-09 18:36:48 +05:30
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-08-22 19:58:39 +05:30
|
|
|
case "$(file -biL "$entry")" in
|
|
|
|
*text*)
|
|
|
|
"${VISUAL:-$EDITOR}" "$entry" ;;
|
|
|
|
*)
|
2020-08-20 03:21:26 -06: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 19:58:39 +05:30
|
|
|
esac
|