-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/google
Copy pathMore file actions
executable file
·72 lines (59 loc) · 1.22 KB
/google
File metadata and controls
executable file
·72 lines (59 loc) · 1.22 KB
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
#!/bin/bash
# REMINDER: Hold down Shift to copy text from elinks
if [[ $# -lt 1 ]]
then
echo
echo "$0: Do google search from within the terminal."
echo "This script output can also be piped to other applications"
echo "Usage: $0 search query"
echo
exit
fi
if [ ! -t 1 ]; then
# Output is piped to another application
to_stdout=1
fi
ord()
{
printf "%d" "'$1"
}
hex()
{
printf "%x" "$1"
}
char_to_html()
{
_char=$1
_code=$((`printf "%d" "'$char"`))
if [ $_code -ge $(ord а) ] && [ $_code -le $(ord я) ]
then
_code=$(( _code - $(ord а) + 0xe0 ))
_char=%$(hex $_code)
fi
if [ $_code -ge $(ord А) ] && [ $_code -le $(ord Я) ]
then
_code=$(( _code - $(ord А) + 0xc0 ))
_char=%$(hex $_code)
fi
echo $_char
}
to_html()
{
str="$1"
output=""
for (( i = 0; i < ${#str}; i++ ))
do
char="${str[@]:$i:1}"
output+=$(char_to_html $char)
done
echo $output
}
search_str="$(echo $@ | sed 's/ /+/g')"
query="https://www.google.ru/search?q=${search_str}"
echo $search_str
export TERM=xterm
if (( to_stdout == 0 )); then
elinks "$query"
else
curl --location -A "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0" "$query"
fi