git-substitute

command module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2014 License: MIT Imports: 7 Imported by: 0

README

git-substitute

the stupid search and replacer

Latest Version Build Status

Installation

Download the appropriate binary for your OS and architecture and unzip it to somewhere in your $PATH.

Alternately, if you've already installed Go, and $GOPATH/bin is in your $PATH, then just:

$ go get github.com/nicknovitski/git-substitute

Usage

Pass a search pattern and a replacement string to replace text matching the former with the latter.

$ git substitute foo bar # "foo" -> "bar"

Pass one or more paths to restrict the substitution to just those paths.

$ git substitute Command Demand bin doc # "Command" -> "Demand", but only in bin/ and doc/

Wrap quotes around arguments with spaces or other shell metacharacters in them.

$ git substitute 'to boldy go' 'to go boldly'

The search pattern argument is an extended regex, interpreting metacharacters (\^$.|?*()[]{}), while the replacement argument treats them literally.

$ git substitute peoples? persons? # "people" & "peoples" -> "persons?"

Thus, to search for those characters as literals, escape them with a backslash and wrap quotes around the argument (technically you don't have to always do that second bit, but the alternative is even more backslashes, and ugh to that).

$ git substitute '50\.00' 49.99 # '50.00' -> '49.99'

The replacement argument recognizes one kind of metacharacter: group references, in the form \1, \2, etc.

git substitute '\bUser\.find_by_name\((.*)\)' 'User.where(name: \1).first'

Finally, before you dive in, may I recommend an alias to git sub? It's much less typing.

git config --global alias.sub substitute

I would have just named the command sub, but:

  1. The other git commands are all complete English words.
  2. SEO.

Acknowledgments

I can't remember when I first read jason meredith's blog post explaining the "grep -l pipe xargs sed -i s" method, but I remember many times since then when it's enabled me to trivially accomplish enormous things. Thanks, Jason. You've given me leverage.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL