fuzz-search-file (445B)
1 #!/usr/bin/env bash 2 set -eo pipefail 3 4 file="$1" 5 if [ -n $1 ]; then 6 if [ ! -f "$1" ]; then 7 file=$(rg --files | fuzzer "$1") 8 fi 9 else 10 file=$(rg --files | fuzzer) 11 fi 12 13 14 file=$(readlink -f "$file") 15 q="" 16 if [ -n "$2" ] && [ "$2" != "" ]; then 17 q="--query '$2'" 18 fi 19 20 linecmd="awkt '{print \$0, NR}' '$file' | fzf --ansi --tac $q | sed -En 's,.*\t([0-9]+)$,\1,p'" 21 num=$(eval $linecmd) 22 echo ${3:-$EDITOR} +$num \"$file\" "# $(sed -n ${num}p "$file")"