-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathg
executable file
·48 lines (47 loc) · 1.14 KB
/
g
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
#!/bin/bash
#
# Quick grep based on `ripgrep` (rg), `ack`, or `grep`.
# > More information: <https://github.com/BurntSushi/ripgrep> or `help rg`.
#
# - Recursively search the current folder for a regex pattern:
#
# `g {{pattern}}`
#
# - Search for a pattern only in a certain filetype (e.g., html, css, etc.):
#
# `g -t {{file type}} {{pattern}}`
#
# - Search for a pattern in files matching a glob (e.g., `README.*`):
#
# `g -g {{glob}} {{pattern}}`
#
# - Match only at word boundaries:
#
# `g -w {{pattern}}`
#
# - Case-sensitive search:
#
# `g -s {{pattern}}`
#
# - Search for a pattern only in a file or folder:
#
# `g {{pattern}} {{file or folder}}`
#
# - Replace a pattern (will only print results, use `wg` to do the actual replace):
#
# `g {{pattern}} {{filename}} --replace {{replacement}}`
#
# ---
# Based on https://github.com/sapegin/dotfiles/blob/master/bin/g
#
# Author: Nick Plekhanov, https://nikkhan.com/
# License: MIT
# https://github.com/nicksp/dotfiles
if command -v rg &> /dev/null; then
# See tilde/.ripgreprc for default options
rg --json -C 2 "$@" | delta
elif command -v ack &> /dev/null; then
ack -ri "$@"
else
grep -ri "$@"
fi