Skip to content

Instantly share code, notes, and snippets.

@nkh
Created March 30, 2020 16:38
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 nkh/4cddff5d8d0a011e33da0630ff469162 to your computer and use it in GitHub Desktop.
Save nkh/4cddff5d8d0a011e33da0630ff469162 to your computer and use it in GitHub Desktop.
#!/bin/bash
# functions moved in a script so they can be used by fzf preview
# arg_n: echo "$2" | cut -d : -f $1
# minus_limit: test $(($number - $minus)) -le $limit && echo $limit || echo $(($number - $minus))
match=$( \
rg --no-heading -n --color=always --colors 'match:style:nobold' --colors 'match:fg:white' $* . | \
plc --values | \
fzf -e -m \
--color="hl:51" \
--ansi \
--preview-window='top:50%' \
--preview 'file=$(arg_n 1 {}) line=$(arg_n 2 {}) && echo "$file" | \
plc && \
bat --theme="TwoDark" --highlight-line $line --tabs=4 -n --color=always "$file" \
-r $(minus_limit $line 4 1):'
)
[[ -z "$match" ]] && exit
IFS=$'\n'
while read l ; do
files+=("+tabnew +$(arg_n 2 "$l") $(arg_n 1 "$l")")
done <<< "$match"
vi $(tempfile) ${files[@]} +tabnext +q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment