Grep, Ack, Ag 使用記錄


發現 AG 這東西,所以一并記錄一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Grep 裡面要無視某目錄
# 但 --exclude-dir=dir 需要 GNU Grep >= 2.5.2
grep -ri --exclude-dir=.git [someWords] *.java

# 所來玩一下 ACK 這東西
# 安裝和使用
brew install ack
ack --java --no-heading [someWords]

# 關於顏色方面用這方法查看
網址: http://perldoc.perl.org/Term/ANSIColor.html
裡面: Function Interface 裡面
- recognized normal foreground color
- recognized normal background color

# 簡單設定一下
echo "--smart-case" >> ~/.ackrc
echo "--heading" >> ~/.ackrc
echo "--flush" >> ~/.ackrc
echo "--color-line=lightblue" >> ~/.ackrc
echo "--color-match=on_blue" >> ~/.ackrc
echo "--all-types" >> ~/.ackrc

# 最後就可以簡化執行
ack --java [someWords]

# 再來安裝 ag 這個比 grep, ack 還快的玩意
brew install the_silver_searcher

# 安裝過程中可能會出現這種錯誤
checking for style of include used by make... GNU
checking dependency style of cc... none
checking whether make supports nested variables... yes
./configure: line 3911: syntax error near unexpected token `PCRE,'
./configure: line 3911: `PKG_CHECK_MODULES(PCRE, libpcre)'

Error: the_silver_searcher did not build
Logs: /Users/[用戶]/Library/Logs/Homebrew/the_silver_searcher/
Help: https://github.com/mxcl/homebrew/wiki/troubleshooting

# 解決方法,重新建立 PKG 的軟鏈接,並重裝
brew link pkg-config
brew install the_silver_searcher

# 如果還不行就
source ~/.bash_profile 或 csh && bash
brew link pkg-config
brew install the_silver_searcher

# 簡單測試一下,搜尋當前目錄內的 WORD
# 參數都很像 ack,不過好像沒有 .ackrc?
ag [someWords]
ag -a -S [someWords]

參考:
http://bootleq.blogspot.tw/2012/09/ack.html