edgrep

Populate $EDITOR with files that match content search
git clone git://git.deurzen.net/edgrep
Log | Files | Refs

commit ac889576d46be934415bb3872667fd91057507e2
Author: deurzen <max@deurzen.net>
Date:   Wed, 25 May 2022 05:18:46 +0200

initial commit

Diffstat:
Aeg | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/eg b/eg @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -Eeo pipefail + +if [ $# -eq 0 ]; then + 1>&2 echo "no arguments provided" + exit 1 +fi + +REGEX="$1" +shift + +MATCHES="`ag -l --no-color "${REGEX}" $@`" + +if test -z "${MATCHES}"; then + 1>&2 echo "no results match regex" + exit 2 +else + if [[ $EDITOR == *vim ]]; then + eval $EDITOR +/\"${REGEX}\" ${MATCHES} + else + eval $EDITOR ${MATCHES} + fi +fi