From 5c916d69d457101326803eb076a746060e3618cf Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Thu, 21 Nov 2024 13:30:52 +0530 Subject: Moved from github --- .local/bin/fgrp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 .local/bin/fgrp (limited to '.local/bin/fgrp') diff --git a/.local/bin/fgrp b/.local/bin/fgrp new file mode 100755 index 0000000..ddf3448 --- /dev/null +++ b/.local/bin/fgrp @@ -0,0 +1,27 @@ +#!/bin/sh + +# fzf-grep: browse through grepped lines using fzf + +if [ "$OPENFLAG" = 0 ]; then + location="$(echo "$*" | sed 's/^\(.*\):\([0-9]\+\):.*$/\1|\2/')" + file="${location%|*}"; line="${location##*|}" + case "${OPENWITH:=$EDITOR}" in + ''|vi|*vim*) $OPENWITH +"$line" "$file" ;; + *) $OPENWITH "$file" ;; + esac; exit +fi + +mkdir -pv "${XDG_DATA_HOME:=$HOME/.local/share}/fzf" +export FZF_HIST="$XDG_DATA_HOME/fzf/grep_history" +grep -Rnsi --exclude-dir=.git --exclude-dir=node_modules --color=always "$@" | + fzf --ansi \ + --history="$FZF_HIST" \ + --prompt="grep > " \ + --preview='preview "$(echo {1} | cut -d: -f1)"' \ + --preview-window="hidden" \ + --bind 'ctrl-v:toggle-preview,ctrl-space:toggle-preview' \ + --bind "ctrl-r:reload(grep -Rns --color=always $*)" \ + --bind 'enter:execute(echo {} >> "$FZF_HIST"; OPENFLAG=0 fgrp {})' \ + --bind 'alt-e:execute(echo {} >> "$FZF_HIST"; OPENFLAG=0 OPENWITH=${EDITOR:-vi} fgrp {})' \ + --bind 'alt-o:execute(echo {} >> "$FZF_HIST"; OPENFLAG=0 OPENWITH=${OPENER:-xdg-open} fgrp {})' \ + --bind 'alt-O:execute(echo {} >> "$FZF_HIST"; OPENFLAG=0 OPENWITH=${FILES:-lf} fgrp {})' -- cgit v1.2.3