GithubHelp home page GithubHelp logo

goreplace's Introduction

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:

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

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 builds and compiled byte-codes (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

Binary builds (64 bit):

It's suited to be installed via go tool, so you can do usual 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.

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?). Unfortunately only plain strings are supported as replacement, no regexp submatch support yet (planned, though).

goreplace's People

Contributors

piranha avatar

Watchers

Areski Belaid avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.