-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
g
executable file
·46 lines (44 loc) · 1.05 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
#!/usr/bin/env bash
# Quick grep (based on ripgrep).
# > 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 actual replace):
#
# `g {{pattern}} {{filename}} --replace {{replacement}}`
#
# ---
# Author: Artem Sapegin, sapegin.me
# License: MIT
# https://github.com/sapegin/dotfiles
if command -v rg > /dev/null 2>&1; then
# See tilde/ripgreprc for default options
rg --json -C 2 "$@" | delta
elif command -v ack > /dev/null 2>&1; then
ack -ri "$@"
else
grep -ri "$@"
fi