-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathigrep
executable file
·78 lines (77 loc) · 2.66 KB
/
igrep
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
#!/bin/sh
if [ -z "$1" ]; then
echo
echo "Error: You must Specify a search term."
echo
fi
#_grep_param1="$1"
#_grep_param2="$2"
#_grep_param3="$3"
#_grep_param4="$4"
#_grep_param5="$5"
#_grep_param6="$6"
#_grep_param7="$7"
#_grep_param8="$8"
_results=/tmp/igrep-output.txt
echo "" > $_results
if [ $? -ne 0 ]; then
echo "writing $_results failed."
exit 1
fi
_grep_h="-H"
_grep_r="-r"
_grep_n="-n"
_param_i=1
for var in "$@"
do
if [ "@$var" = "@-H" ]; then
_grep_h=""
# There was already an -H param, so don't add one.
elif [ "@$var" = "@-r" ]; then
_grep_r=""
# There was already an -r param, so don't add one.
elif [ "@$var" = "@-n" ]; then
_grep_n=""
# There was already an -n param, so don't add one.
fi
_param_i=$((_param_i + _param_i))
# ^ See <https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script>
done
# for hexchat_path in ~/.config/hexchat-bad ~/.config/hexchat-bad2 ~/.config/hexchat
hexchat_path=~/.config/hexchat
if [ ! -d "$hexchat_path/logs" ]; then
alt_path="$HOME/.config/hexchat.deactivated-use.weechat.instead"
if [ -d "$alt_path/logs" ]; then
hexchat_path="$alt_path"
>&2 echo "* using \"$hexchat_path\""
else
>&2 echo "* no \"$alt_path\""
fi
else
>&2 echo "* using \"$hexchat_path\""
fi
# for logname in "ircnow for minetest etc by jrmu via oldcoder" irc.oldcoder.org "minetest.io irc bouncer"
# ~~Use "find" to get the full path (See <https://stackoverflow.com/questions/246215/how-can-i-generate-a-list-of-files-with-their-absolute-path-in-linux>).~~
# - find doesn't handle spaces in filenames well
# Use `for dir in */` since that handles spaces in filenames (See <https://stackoverflow.com/questions/4895484/loop-over-directories-with-whitespace-in-bash>).
cd "$hexchat_path/logs"
for logname in */
do
echo
echo "* searching $logname..."
# cat <<END
# grep "$@" -r "$logpath" >> "$_results"
#END
# grep $_grep_param1 $_grep_param2 $_grep_param3 -r "$hexchat_path/logs/$logname" >> "$_results"
echo grep "$@" $_grep_r $_grep_h $_grep_n "$logname"
#cd /
grep "$@" $_grep_r $_grep_h $_grep_n "$hexchat_path/logs/$logname" >> "$_results"
# ^ -H (to show the full path) doesn't work unless the full path is specified.
# ^ You must quote "$@" or bash will "revert to the broken $* semantics" according to
# tripleee on <https://stackoverflow.com/questions/4824590/propagate-all-arguments-in-a-bash-shell-script>
# grep $_grep_param1 $_grep_param2 $_grep_param3 -r "$hexchat_path/logs/$logname"
done
cat $_results
echo "outputinspector \"$_results\""
outputinspector "$_results"
rm "$_results"