-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgrep-shortcuts
More file actions
executable file
·42 lines (36 loc) · 889 Bytes
/
grep-shortcuts
File metadata and controls
executable file
·42 lines (36 loc) · 889 Bytes
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
#!/bin/bash
me="grep-shortcuts"
mode=`basename $0`
if [ "$mode" = "$me" ] && [ -z "$*" ]; then
here=`dirname $0`
if [ -z "$ZDOTDIR" ]; then
echo "\$ZDOTDIR not set; aborting." >&2
exit 1
fi
echo -n "Setting up handy grep shortcuts in $here ..."
cd "$here"
# see also global aliases in .zshrc
for switches in '' {,i}{,l,L}{,r,R}{,v}{,C}; do
cmd=g$switches
preexisting=$( which $cmd 2>/dev/null )
if [ $? = 0 ] && [ "$ZDOTDIR/bin/$cmd" != "$preexisting" ]; then
echo -ne "\nWARNING! $cmd already found on path" >&2
fi
if ! [ -e $cmd ]; then
ln -s $me $cmd
echo -n " $cmd"
fi
done
echo
exit 0
fi
switches="${mode#g}"
color=
case "$switches" in
*C*)
switches="${switches//C/}"
color=--color=always
;;
esac
[ -n "$switches" ] && switches=-$switches
exec grep -E $switches $color "$@"