Created
August 3, 2022 23:16
-
-
Save wridgers/309671097fa599ced8b92e2e4916b3fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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