Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Last active October 23, 2017 15:53
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 gilbertw1/0bd25fac2d4a8fc016fd7c6f3978ff19 to your computer and use it in GitHub Desktop.
Save gilbertw1/0bd25fac2d4a8fc016fd7c6f3978ff19 to your computer and use it in GitHub Desktop.
Awesome rg search
#!/bin/sh
FILE_LINE_NO="$1"
FILE="$(echo "$FILE_LINE_NO" | cut -d":" -f1)"
SUFFIX="$(echo $FILE | cut -d"." -f2)"
LINE_NO="$(echo "$FILE_LINE_NO" | cut -d":" -f2)"
if [ "$LINE_NO" -gt 10 ]
then
START="$((${LINE_NO} - 10))"
END="$((${LINE_NO} + 10))"
else
START="1"
END="21"
fi
OFFSET="$((${LINE_NO} - ${START} + 1))"
ESC=$(printf '\033')
echo "$(sed -n ${START},${END}p $FILE)" \
| highlight -O xterm256 -s anotherdark -l -m $START -S $SUFFIX --force \
| sed "${OFFSET}s/.*/${ESC}[1;48;5;8m\0${ESC}[0m/" \
| sed "${OFFSET}s/\[m/[1;48;5;8m${ESC}[1;38;5;0m/g"
#!/bin/sh
FILE_LINE_NO=$(sk-tmux --ansi -i -c 'rg -i --no-heading --line-number --color=always "{}"' --preview "preview {0}")
if [ $? -ne 0 ] || [ -z "$FILE_LINE_NO" ]; then
echo "Aborted rip search, exiting..."
exit
fi
FILE="$(echo "$FILE_LINE_NO" | cut -d":" -f1)"
LINE_NO="$(echo "$FILE_LINE_NO" | cut -d":" -f2)"
nvim +$LINE_NO $FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment