Replace text for all git controlled files by ruby gsub.
You can control the gsub replacement with the ruby script.
Inspired by git-gsub
git gsub hoge piyo
git gsub -e '/hoge([0-9]+)/' 'piyo\#{$1.to_i + 1}'
git gsub -e '/belongs_to :(\w+)([^#\n]*)(#.*)?$/' '"belongs_to :#{$1}#{$2.include?("optional: false") ? $2 : $2.strip + ", optional: true"}#{$3 != nil ? " " + $3 : ""}"' 'app/models/**/*.rb'
$ gem install git-gsub-ruby
Edit your .gitconfig file
[alias]
# add new line
gsub = !git-gsub-ruby
Or use git config
$ git config --global alias.gsub '!git-gsub-ruby'
Bug reports and pull requests are welcome on GitHub at https://github.com/katsusuke/git-gsub-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Git::Gsub::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.