-
Notifications
You must be signed in to change notification settings - Fork 151
/
ack.sh
68 lines (36 loc) · 1.29 KB
/
ack.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Like find and grep, but with some features specialized to programming,
# and more convenient in general.
# Nice filename/line/match highlight output.
# Ignores .git .svn, backup, swap files by default.
# Can detect and filter by filetype via extension and shebangs.
## install
sudo aptitude install -y ack-grep
# `ack` package was already taken by a kanji converter!
# this begs for an alias:
alias ack="ack-grep"
# Recursive find grep for perl_regex in python files only, detects shebangs:
ack --py perl_regex
# Adds all python files git. shebang aware:
ack -f --py --print0 | xargs -0 -I '{}' git add '{}'
# Print only include names in cpp files
ack --cc '#include\s+<(.*)>' --output '$1'
# --sh for bash
# `-k`: search in all known filetypes.
# There seems to be no way to search into *all* files.
# Well, we have GNU `grep -r` for that...
## -f
# List all filenames of known types:
ack -f
## -g
# List files of known types that match regex:
ack -g '\.py$'
# Easter egg: bill the cat:
ack --thpppt
## combos
# find lines in files:
ack -f | xargs grep 'find'
# dry run replace in files with regex::
ack -f | xargs -lne 'print if s/a/A/g'
# only prints modified lines
# non-dry run replace in files:
ack -f | xargs perl -pie 's/z/Z/g'