Skip to content

Instantly share code, notes, and snippets.

@wridgers
Created August 3, 2022 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wridgers/309671097fa599ced8b92e2e4916b3fb to your computer and use it in GitHub Desktop.
Save wridgers/309671097fa599ced8b92e2e4916b3fb to your computer and use it in GitHub Desktop.
function ,() {
local dir="."
local search="."
# todo: check for fzf, rg, bat, tree, and fd.
if [ -n "$1" ]; then
if test -f $1; then
$EDITOR $1
return
elif test -d $1; then
local dir=$1
elif [ $1 = "-f" ]; then
# Special find mode.
# todo: don't open if nothing found
# todo: allow picking search dir
${EDITOR} $(rg -n ${2:-.} | fzf --tac --select-1 --exit-0 | awk -F: '{print "+" $2 " " $1}')
return
elif [ $1 = "-t" ]; then
# Special tag mode.
# todo: recursively search all ^tags$ files
${EDITOR} $*
return
else
local search=$1
fi
fi
# todo: exclude larget compressed files
local found=$(
fd --full-path --hidden --exclude .git ${search} ${dir} \
| fzf --tac --select-1 --exit-0 \
--preview="if test -f {}; then
bat --style=numbers --color=always --line-range :150 {}
else
tree -C -L 1 {};
fi"
)
if [ -z "$found" ]; then
return
fi
if test -d ${found}; then
cd ${found}
elif test -f ${found}; then
${EDITOR} ${found}
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment