-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsift-utils.sh
81 lines (67 loc) · 2.07 KB
/
sift-utils.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
if type sift >/dev/null ; then
TRANSLATIONS=$'
s/--near/--surrounded-by/g
s/--not-near/--not-surrounded-by/g
s/--within/--surrounded-within/g
s/--not-within/--surrounded-within/g
s/--before/--preceded-by/g
s/--not-before/--preceded-by/g
s/--after/--followed-by/g
s/--not-after/--followed-by/g
s/--file-has/--file-matches/g
s/--file-has/--file-matches/g
'
siftplus () {
local ARGS=()
local DRY_RUN=
local ALL_OPTS
local HELP=
for ARG ; do
if [[ $ARG == "--" ]] ; then
break
elif [[ $ARG == "--trace" ]] ; then
local TRACE=1
fi
done
for ARG ; do
if [[ $TRACE ]] ; then
echo -e "\nARG=$ARG"
fi
if [[ $ARG == "--" || $NO_MORE_OPTIONS ]] ; then
local NO_MORE_OPTIONS=1
elif [[ $ARG == "--dry-run" ]] ; then
DRY_RUN=1
continue
elif [[ $ARG == "--trace" ]] ; then
continue
elif [[ $ARG == "--help" || $ARG == "-h" || $ARG == "-?" ]] ; then
HELP=1
else
ARG="$(echo $ARG | sed -e "$TRANSLATIONS")"
fi
ARGS+=($ARG)
if [[ $TRACE ]] ; then
echo "ARGS=$ARGS"
fi
done
if [[ $DRY_RUN ]] ; then
echo sift ${ARGS[@]}
else
command sift ${ARGS[@]}
if [[ $HELP ]] ; then
echo "$(tput setaf 6)Option Aliases$(tput sgr0)"
echo "$(tput setaf 6) --near=PATTERN same as --surrounded-by$(tput sgr0)"
echo "$(tput setaf 6) --within=PATTERN same as --surrounded-within$(tput sgr0)"
echo "$(tput setaf 6) --before=PATTERN same as --preceded-by$(tput sgr0)"
echo "$(tput setaf 6) --after=PATTERN same as --followed-by$(tput sgr0)"
echo "$(tput setaf 6) --file-has=PATTERN same as --file-matches$(tput sgr0)"
fi
fi
}
alias sift=siftplus
alias sift!='command sift'
# if which compdefd >/dev/null ; then
# compdef _siftplus siftplus=sift
# fi
fi