• Stars
    star
    184
  • Rank 209,187 (Top 5 %)
  • Language
    Go
  • License
    ISC License
  • Created over 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

command line tool for search and replace

Go Replace

Go Replace (gr) is a simple utility which can be used as replacement for grep + sed combination in one of most popular cases - find files, which contain something, possibly replace this with something else. Main points:

  • Reads .hgignore/.gitignore to skip files
  • Skips binaries
  • Familiar PCRE-like regexp syntax
  • Can perform replacements
  • Fast

Bonus:

  • Can search in file names with -f (i.e. a simple alternative to find)

Build Status

Releases and changelog

Why

Why do thing which is done by grep, find, and sed? Well, for one - I grew tired of typing long commands with pipes and ugly syntax. You want to search? Use grep. Replace? Use find and sed! Different syntax, context switching, etc. Switching from searching to replacing with gr is 'up one item in history and add a replacement string', much simpler!

Besides, it's also faster than grep! Hard to believe, and it's a bit of cheating - but gr by default ignores everything you have in your .hgignore and .gitignore files, skipping binary files and compiled bytecodes (which you usually don't want to touch anyway).

This is my reason to use it - less latency doing task I'm doing often.

Installation

Just download a suitable binary from release page. Put this file in your $PATH and rename it to gr to have easier access.

Building from source

You can also install it from source, if that's your thing:

go get github.com/piranha/goreplace

And you should be done. You have to have $GOPATH set for this to work (go will put sources and generated binary there). Add -u flag there to update your gr.

I prefer name gr to goreplace, so I link gr somewhere in my path (usually in ~/bin) to $GOPATH/bin/goreplace. NOTE: if you use oh-my-zsh, it aliases gr to git remote, so you either should use another name (I propose gor) or remove gr alias:

mkdir -p ~/.oh-my-zsh/custom && echo "unalias gr" >> ~/.oh-my-zsh/custom/goreplace.zsh

Usage

Usage is pretty simple, you can just run gr to see help on options. Basically you just supply a regexp (or a simple string - it's a regexp always as well) as an argument and gr will search for it in all files starting from the current directory, just like this:

gr somestring

Some directories and files can be ignored by default (gr is looking for your .hgignore/.gitignore in parent directories), just run gr without any arguments to see help message - it contains information about them.

And to replace:

gr somestring -r replacement

It's performed in place and no backups are made (not that you need them, right? You're using version control, aren't you?). Regular expression submatches supported via $1 syntax - see re2 documentation for more information about syntax and capabilities.

More Repositories

1

gostatic

Fast static site generator
Go
449
star
2

twinspark-js

Declarative enhancement for HTML: simple, composable, lean.
JavaScript
412
star
3

keymage

Yet Another JS Keybinding library
JavaScript
333
star
4

keybind

ClojureScript key bindings (shortcut) library
Clojure
84
star
5

nomad

simple sql migration tool to save you from going mad
Python
77
star
6

pump

Pump your REACTive app with fuel
JavaScript
75
star
7

puttext

Gettext-like i18n library for javascript
JavaScript
57
star
8

opster

Command line parsing speedster
Python
51
star
9

webhooker

github webhook handler
Go
49
star
10

ring-undertow-adapter

Ring server built with Undertow
Clojure
48
star
11

cyrax

Static site generator
Python
42
star
12

adium-inline-images

Adium Image Inliner
JavaScript
23
star
13

showkr

Minimalistic photo viewer
Clojure
23
star
14

snakeq

Snake, oh, snake, oh, it's a snake
Clojure
18
star
15

infowarship

Script for showing information popup for Russian IPs.
HTML
18
star
16

ecomspark

TwinSpark example
Clojure
17
star
17

piu.clj

Simple pastebin
Clojure
16
star
18

shorrt

Simple app for global keybindings on OS X
Objective-C
12
star
19

mesto

In-memory storage for ClojureScript. Seems to be working.
Clojure
10
star
20

tnetstrings.js

tnetstrings javascript implementation
JavaScript
7
star
21

webhook-action

Minimal dependencies webhook step for Github Actions
JavaScript
7
star
22

conf

My configuration files
Emacs Lisp
6
star
23

piu

deprecated, see newer version in Clojure
Python
6
star
24

solovyov.net

My site
HTML
5
star
25

om-snake

Simplest snake in om
Clojure
5
star
26

tunatron

Simple and fast iTunes controlling app
Objective-C
3
star
27

slides

HTML
2
star
28

imap2sockjs

Go
2
star
29

piranha

Clojure
1
star
30

xapicms

Headless CMS sporting Ghost API and an ability to send webhooks
Clojure
1
star
31

stream-progress

Clojure
1
star
32

rumsnake

Basic snake game in CLJS
Clojure
1
star
33

passync

Python
1
star
34

highlight.exe

"binary" for highlight.js
JavaScript
1
star
35

b2ls

Cloudflare worker to share private Backblaze B2 bucket
JavaScript
1
star