Github is just code with no context! Find out more:
- follow me on Twitter @asolovyov
- subscribe to my Telegram channel @bitethebyte (it's in Ukrainian)
- read my blog
Here are latest posts from the blog:
command line tool for search and replace
License: ISC License
Github is just code with no context! Find out more:
Here are latest posts from the blog:
regexp.Expand
is available now for that.
% gr secure
app/states/signin.jade
2:input(placeholder="Password", secure, key="password")
app/states/signup.jade
2:input(placeholder="Password", secure, key="password")
css/elements.less
84: &[secure] {
Have no idea what it depends on, but I faced this bug three times at least (using gr daily for few weeks).
And making it output colors means cgo, which means I won't be able to cross-compile.
Simpler solution for now is just removing colors when writing something on Windows.
I am using version 2.3 and using this file:
@alert, url: [:admin
gr admin
output
2014/09/05 18:19:10 Wrong color syntax: a
Допустим есть такой код:
# где-то в 9 строке:
foo
# где-то в 185 строке:
foo
foo
gr
по фразе foo
найдет три строки (9, 185 и 186) и напечатает их с сохранением отсутпов, но номер строки 9 занимает 1 символ, а 185-186 — три, тем самым визуально добавляя еще по два пробела к 185 и 186 относительно 9:
9: foo
185: foo
186: foo
Злит неимоверно :) Как насчет такого?
9 : foo
185: foo
186: foo
So that you can add some specific files which are tracked by VCS, but which should not be touched. It should be collected recursively (i.e. find one at repo root, one at your homedir, merge them).
For example: find --name "*.py" | grep abcd
I couldn't find a way to do this.
did I miss it?
GoReplace поддерживает в поисковых запросах регэкспы?
Я попробовал искать, результат:
C:\U\e\Projects\m-s\src\blog> gr -c "layouts"
2009-05-18-awesome-nastrojka.markdown
17: layouts =
2010-11-13-jekyll-hyde.markdown
28: |-- _layouts
40:<strong>_layouts</strong> - это каталог, содержащий используемые шаблоны страниц. Обычно это два шаблона, использующих язык разметки Liquid.
2013-04-20-jekyll-tags.markdown
35:Теперь в директории `_layouts` создаем файл `tag_page.html`, пример кода данной страницы есть на странице расширения, я же использовал следующий вариант:
C:\U\e\Projects\m-s\src\blog> gr -c "^<"
C:\U\e\Projects\m-s\src\blog> gr -c "^\<"
C:\U\e\Projects\m-s\src\blog> gr -c "^/<"
C:\U\e\Projects\m-s\src\blog>
Первый поиск показал, что есть строка, как минимум одна, которая начинается с символа открытия треугольной скобки. При попытке задать в поиске параметр содержания символа в начале строки получаем нулевой результат.
Выходит в поиске нет возможности использовать регэкспы? Или используется какой-то свой язык?
Подобный же вопрос касается описания программы. Указывается, что используется функции grep и sed. По grep задал вопрос выше, и кстати, проверил запрос, описанный выше, именно в grep, получил массу строк в результате.
sed использует в своем функционале свой собственный язык поиска и замены. Что именно из языка sed было реализовано в GoReplace?
Something like:
-l, --only-lines=RE apply replace only on lines that match a pattern
So that you can easily scope your search-and-replace to only apply on certain lines if you're replacing a common phrase.
~/p/test (master) goreplace
Usage of goreplace 0.4.3:
gr [OPTS] string-to-search
Ignoring patterns from test/.gitignore:
globs: .bundle /db/.sqlite3 /log/ /tmp/* .DS_Store .rbenv-gemsets .powenv /public/uploads/** /public/assets
~/p/test (master) goreplace aws -n
Skipping log/development.log, too big: 38096819
Skipping log/test.log, too big: 395531579
tmp/cache/assets/D5D/A70/sprockets%2Fe8712ded68ed3a8ac1b18ac400244c32
tmp/cache/assets/D6E/0E0/sprockets%2Feaaea015e64217c9ff78f24eba681651
tmp/cache/assets/E2E/9A0/sprockets%2F6fdcccd483dc6dbc7fc31adb80d50668
And it should not, it should only ignore everything starting with dot.
So that you can review what are you replacing and optionally edit replacement line.
Apparently it started after upgrading to macOS 10.12:
andrey@andreymac ~/work/prophy/prophy> gr 'get_article2tfidf_vector'
Skipping datalib/tests/testdata/sw_ontology.json, too big: 13859118
src/prophy/clusters/article_metrics.py
79:def get_article2tfidf_vector(article2property: TArticle2Property,
116: return get_article2tfidf_vector(article2property=article2property,
Skipping src/tests/latex_archives/with_text_and_refs/1203.3562v1, too big: 11284480
failed MSpanList_Insert 0x279c00 0x947226add66d 0x0
fatal error: MSpanList_Insert
goroutine 16 [running]:
runtime.throw(0x22ca1b)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/panic.c:520 +0x69 fp=0xc20807f060 sp=0xc20807f048
runtime.MSpanList_Insert(0x242c28, 0x279c00)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/mheap.c:618 +0x8a fp=0xc20807f088 sp=0xc20807f060
MHeap_FreeLocked(0x23ec20, 0x279c00)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/mheap.c:447 +0x1a6 fp=0xc20807f0c8 sp=0xc20807f088
MHeap_AllocLocked(0x23ec20, 0x156, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/mheap.c:257 +0x288 fp=0xc20807f108 sp=0xc20807f0c8
runtime.MHeap_Alloc(0x23ec20, 0x156, 0x10100000000)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/mheap.c:178 +0x7b fp=0xc20807f130 sp=0xc20807f108
largealloc(0xc200000001, 0xc20807f1e0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/malloc.goc:224 +0xa2 fp=0xc20807f178 sp=0xc20807f130
runtime.mallocgc(0x2aa800, 0x107141, 0x1)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/malloc.goc:169 +0xb6 fp=0xc20807f1e0 sp=0xc20807f178
cnew(0x107140, 0x2aa800, 0x1)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/malloc.goc:836 +0xc1 fp=0xc20807f200 sp=0xc20807f1e0
runtime.cnewarray(0x107140, 0x2aa800)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/malloc.goc:849 +0x3a fp=0xc20807f220 sp=0xc20807f200
makeslice1(0x1000e0, 0x2aa800, 0x2aa800, 0xc20807f280)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/slice.goc:55 +0x4d fp=0xc20807f238 sp=0xc20807f220
runtime.makeslice(0x1000e0, 0x2aa800, 0x2aa800, 0x0, 0x2aa800, 0x2aa800)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/slice.goc:36 +0xb3 fp=0xc20807f268 sp=0xc20807f238
main.(*GRVisitor).GetFileAndContent(0xc208025320, 0xc208036f40, 0x38, 0x283488, 0xc208168230, 0xc208038050, 0x0, 0x0, 0x0)
/Users/piranha/dev/go/src/goreplace/goreplace.go:235 +0x125 fp=0xc20807f360 sp=0xc20807f268
main.(*GRVisitor).VisitFile(0xc208025320, 0xc208036f40, 0x38, 0x283488, 0xc208168230)
/Users/piranha/dev/go/src/goreplace/goreplace.go:190 +0x3d9 fp=0xc20807f4b8 sp=0xc20807f360
main.(*GRVisitor).Walk(0xc208025320, 0xc208036f40, 0x38, 0x283488, 0xc208168230, 0x0, 0x0, 0x0, 0x0)
/Users/piranha/dev/go/src/goreplace/goreplace.go:148 +0x137 fp=0xc20807f4f8 sp=0xc20807f4b8
main.*GRVisitor.Walk·fm(0xc208036f40, 0x38, 0x283488, 0xc208168230, 0x0, 0x0, 0x0, 0x0)
/Users/piranha/dev/go/src/goreplace/goreplace.go:121 +0x7f fp=0xc20807f548 sp=0xc20807f4f8
path/filepath.walk(0xc208036f40, 0x38, 0x283488, 0xc208168230, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:343 +0x8c fp=0xc20807f690 sp=0xc20807f548
path/filepath.walk(0xc208174ae0, 0x2b, 0x283488, 0xc208168410, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:368 +0x4f5 fp=0xc20807f7d8 sp=0xc20807f690
path/filepath.walk(0xc2081ba1c0, 0x18, 0x283488, 0xc208168140, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:368 +0x4f5 fp=0xc20807f920 sp=0xc20807f7d8
path/filepath.walk(0xc208000d10, 0x9, 0x283488, 0xc208168eb0, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:368 +0x4f5 fp=0xc20807fa68 sp=0xc20807f920
path/filepath.walk(0xc2080815d5, 0x3, 0x283488, 0xc20841bcc0, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:368 +0x4f5 fp=0xc20807fbb0 sp=0xc20807fa68
path/filepath.walk(0x15bdd0, 0x1, 0x283488, 0xc20801ae60, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:368 +0x4f5 fp=0xc20807fcf8 sp=0xc20807fbb0
path/filepath.Walk(0x15bdd0, 0x1, 0xc20807fda8, 0x0, 0x0)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/path/filepath/path.go:390 +0xe5 fp=0xc20807fd60 sp=0xc20807fcf8
main.searchFiles(0xc2080840a0, 0x283538, 0xc208054680, 0x283628, 0xc20801ac30)
/Users/piranha/dev/go/src/goreplace/goreplace.go:121 +0xda fp=0xc20807fdc0 sp=0xc20807fd60
main.main()
/Users/piranha/dev/go/src/goreplace/goreplace.go:101 +0x69a fp=0xc20807ff50 sp=0xc20807fdc0
runtime.main()
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/proc.c:247 +0x11a fp=0xc20807ffa8 sp=0xc20807ff50
runtime.goexit()
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/proc.c:1445 fp=0xc20807ffb0 sp=0xc20807ffa8
created by _rt0_go
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/asm_amd64.s:97 +0x120
goroutine 19 [finalizer wait]:
runtime.park(0x1ce00, 0x22f230, 0x22e5e9)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x22f230, 0x22e5e9)
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/local/Cellar/go/1.3.1/libexec/src/pkg/runtime/proc.c:1445
zsh: exit 2 gr 'get_article2tfidf_vector'
Looks like both goreplace 2.3 and 2.4 are affected (haven't tried other versions).
I'm seeing the following runtime error:
$ ls -l
total 4
-rw------- 1 501 501 229 Jun 17 12:53 sess_v4ash3jjtkg8nueb2bhbf4ic50
$ gr test
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x44bddc]
goroutine 1 [syscall]:
syscall.Syscall()
/usr/lib/go/src/pkg/syscall/asm_linux_amd64.s:16 +0x5
The directory is a sub-directory of an sshfs mount point and the user/group 501 is not the sshfs user so gr doesn't have permission to read the file.
To try and replicate I created an unreadable file locally but gr didn't error so I'm not sure specifically what combination of things is required to trigger the error.
I'm running Ubuntu 13.04 64bit, go version 1.1 and goreplace version 1.2.
It's impossible to delete stuff, since goopt doesn't recognize empty strings as strings.
If I'm trying to search for something in a generated artefacts of my application, I don't really want to add -I
all the time to the option list.
I often use gr
to do a quick search but sometimes it would be useful to know the context of what is found by looking at the surrounding lines. Adding something like grep's -A
, -B
and -C
flags would be useful.
I know I can combine them into single REs but I want to have aliases to often used searches and multiple -o / -x would allow me to refine these searches.
A nogroup option would allow clicking on the path:line_number to open the file in terminals that support it.
(NB: ag
and pt
both have this option with the name nogroup
so using the same name would avoid having to remember different names when switching between tools)
On my zsh shell with "oh my zsh" plugin, "gr" is an alias for "git remote"
https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/git/git.plugin.zsh
This plugin is popular, so maybe there should be an alternative alias too. Bet you didn't see that one coming.
Suggests: "grp", "grc"
Ofcourse I can have any alias I want. But you know, nice if you propose it.
Please add homebrew formula if possible
Downloading 1.11 and running gr --version
shows goreplace 1.10
. Would have sent a PR to update https://github.com/piranha/goreplace/blob/master/goreplace.go#L21 but not sure if you want it at 1.11 or 1.12?
I'm getting an odd error: Can't read file 'CMSADMIN/tinymce3/jscripts/tiny_mce': %!s(MISSING)
- It's odd because the path printed is actually a directory, not a file, so I'm not sure why it's trying to be read in the first place in GetFileAndContent()
.
I'm using OSX 10.9.4 + gr osx 64b
Given this file:
hello %username%
gr user
abc.txt
1:hello %!ISSING)[0;39;43musername%!
for example:
models.go going to change
As of now, go-replace
replaces the strings in the files in the current directory, it would be nice to also print out the files without changing them.
For example, this is the current behaviour
go-replace search -r replace
A sed
alternative of what I am looking for
cat * | sed 's/search/replace/'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.