3 ms·
I wrote a zsh version of this: function frg { result=$(rg --ignore-case --color=always --line-number --no-heading "$@" | fzf --ansi \
by benterix 3y ago
I wrote a zsh version of this:
function frg {
result=$(rg --ignore-case --color=always --line-number --no-heading "$@" |
fzf --ansi \
--color 'hl:-1:underline,hl+:-1:underline:reverse' \
--delimiter ':' \
--preview "bat --color=always {1} --theme='Solarized (light)' --highlight-line {2}" \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3')
file=${result%%:*}
linenumber=$(echo "${result}" | cut -d: -f2)
if [[ -n "$file" ]]; then
$EDITOR +"${linenumber}" "$file"
fi
}
- taude 3y agoAwesome. Thanks. Saved me some time. I haven't used the fzf integration like this.
- Aissen 3y agoI wrote a fish version, and simplified it: function frg --description "rg tui built with fzf and bat" rg --ignore-case --color=always --line-number --no-heading "$argv" | fzf --ansi \ --color 'hl:-1:underline,hl+:-1:underline:reverse' \ --delimiter ':' \ --preview "bat --color=always {1} --theme='Solarized (light)' --highlight-line {2}" \ --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \ --bind "enter:become($EDITOR +{2} {1})" end Still not a fan of the string-based injections based on the colon and newline characters, but all versions suffer from it. (also: nice that fzf does the right thing and prevents space and quote injection by default).
- 1-more 3y agoI love this, thank you! If anyone else wants to open the file in VScode, the command is code -g "$file:$linenumber"