-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtel-search
More file actions
executable file
·163 lines (151 loc) · 5.34 KB
/
Copy pathtel-search
File metadata and controls
executable file
·163 lines (151 loc) · 5.34 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
# search app for TEL
# v0.4 - by SealyJ
# searx stuff
instance_urls_file=~/.tel/configs/search/searx_trusted.txt
provider_bangs_file=~/.tel/configs/search/provider_bangs.txt
searx_url='list_empty'
function rand_searx_instance () {
n=0
lines_searx_urls=()
while read line;
do
#add to array then select
n=$(( $n + 1 ))
lines_searx_urls+=($line)
done < $instance_urls_file
#select random num from pool
randomiser=$((RANDOM % $n))
selected_url=${lines_searx_urls[$randomiser]} #get url at position
url_site_name_human=$(echo $selected_url | cut -d'/' -f 3)
echo -ne "\e[33;5;2m Engine\e[m: [$url_site_name_human]"
#check if chosen url is up
instance_online=$(timeout 4 curl -I $selected_url 2>&1 | grep -w "200\|301")
while [ -z "$instance_online" ]
do
randomiser=$((RANDOM % $n))
selected_url=${lines_searx_urls[$randomiser]}
url_site_name_human=$(echo $selected_url | cut -d'/' -f 3)
echo -ne "\r\e[33;5;2m Engine\e[m: [$url_site_name_human] "
instance_online=$(timeout 5 curl -I "$selected_url" 2>&1 | grep -w "200\|301")
done
searx_url=$selected_url
}
#end searx specific stuff
# Default behaviour
if [ -z $SEARCH_LOCATION ] ; then
SEARCH_LOCATION='' #gb de it
fi
if [ -z $SEARCH_LANG ] ; then
SEARCH_LANG='en_gb'
fi
if [ -z $SEARCH_PROVIDER ] ; then
SEARCH_PROVIDER='duckduckgo'
SEARCH_URL="https://duckduckgo.com/?q="
bangsymbol="!"
elif [ "${SEARCH_PROVIDER}" == "qwant" ] ; then
SEARCH_URL="https://www.qwant.com/?r=${SEARCH_LOCATION}&l=${SEARCH_LANG}&h=0&s=0&a=1&b=0&vt=0&hc=0&smartNews=1&theme=1&i=1&q="
bangsymbol="&"
elif [ "${SEARCH_PROVIDER}" == "duckduckgo" ] ; then
SEARCH_URL="https://duckduckgo.com/?q="
bangsymbol="!"
elif [ "${SEARCH_PROVIDER}" == "metager" ] ; then
SEARCH_URL="https://metager.org/meta/meta.ger3?eingabe="
bangsymbol="!"
elif [ "${SEARCH_PROVIDER}" == "searx" ] ; then
rand_searx_instance
SEARCH_URL="$searx_url"
bangsymbol="!!"
else
SEARCH_URL="https://duckduckgo.com/?q="
SEARCH_PROVIDER='duckduckgo'
bangsymbol="!"
fi
zsh -c 'set -K' # disables ! events in zsh to allow for bangs in tel-search
if [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then
echo -e "Usage: tel-search [options] [search term]
tel-search = interactive site search prompt
tel-search -h = show this help menu
tel-search -yt 'how to meme' = search in youtube / newpipe app for how to meme
tel-search -t '!w tty' = search wiki using terminal browser
tel-search what are bangs? = search for what are bangs?
tel-search '!gh TEL' = search github for TEL
tel-search '!man echo' = search manpage for echo command info
tel-search '!w sea otters' = search wiki for sea otters
tel-search '!yt vsauce' = search youtube for vsauce
"
exit 0
elif [ "$1" == "-yt" ] ; then
user_query=${@:2}
#youtube_or_newpipe?
cat ~/.app_names | grep -e 'NewPipe' > /dev/null 2>&1
case "$?" in
"1" )
app_to_use="youtube"
;;
*)
app_to_use="newpipe"
;;
esac
if [ "$app_to_use" == "youtube" ] ; then
text=${user_query// /+} #replace spaces with strings
printf "\e[33;5;2m Search \e[m%sYouTube for: $user_query"
yt_url="https://m.youtube.com/results?search_query=$text"
am start -a android.intent.action.MAIN -n 'com.google.android.youtube/com.google.android.apps.youtube.app.application.Shell$UrlActivity' "$yt_url" > /dev/null 2>&1
else
printf "\e[33;5;2m Search \e[m%sNewPipe for: $user_query \n"
am start -a android.intent.action.SEND -t text/plain -e android.intent.extra.TEXT "$user_query" -p org.schabi.newpipe > /dev/null 2>&1
fi
exit 0
elif [ "$1" == "-t" ] ; then
input=${@:2}
text=${input// /%20} #replace spaces with strings
#rand_searx_instance
#"${BROWSER:-links}" "${searx_url}${text}&language=$SEARCH_LANG"
"${BROWSER:-links}" "${SEARCH_URL}${text}"
exit 0
elif [ -z $1 ] ; then
provider=$(cat $provider_bangs_file | fzf -e --color=16 --prompt=" Search site: " --select-1)
if [ -z "$provider" ]; then
# echo 'Nothing selected; exiting...'
exit 1
elif [ "$provider" == "Skip" ]; then
printf "\n\e[33;5;2m Search \e[m%sfor: "
read user_query
input="$user_query"
elif [ "$provider" == "YouTube (in App)" ]; then
printf "\e[33;5;2m Search \e[m%sYouTube for: "
read user_query
text=${user_query// /+} #replace spaces with strings
yt_url="https://m.youtube.com/results?search_query=$text"
am start -a android.intent.action.MAIN -n 'com.google.android.youtube/com.google.android.apps.youtube.app.application.Shell$UrlActivity' "$yt_url" > /dev/null 2>&1
exit 0
elif [ "$provider" != "Skip" ]; then
echo -ne "\r\e[33;5;2m Searching \e[m$provider for: "
#echo -ne "\e[33;5;2m for:\e[m "
read user_query
#provider="!!$provider"
# provider="!$provider"
provider="$bangsymbol$provider"
input="$provider $user_query"
#rand_searx_instance
fi
elif [ "$#" != 0 ] ; then
input="$@"
#rand_searx_instance
#echo -ne "\r\e[33;5;2m Searching \e[m[$url_site_name_human] for: $input"
echo -ne "\r\e[33;5;2m Searching \e[m[${SEARCH_PROVIDER}] for: $input"
fi
# MAIN
main () {
text=${input// /%20} #replace spaces with strings
if [ $(uname -o) == 'Android' ] ; then
#termux-open-url "${searx_url}${text}&language=$SEARCH_LANG"
am start --user 0 -a android.intent.action.VIEW -d "${SEARCH_URL}${text}" > /dev/null
else
#python -m webbrowser -t "${searx_url}${text}&language=$SEARCH_LANG"
python -m webbrowser -t "${SEARCH_URL}${text}"
fi
exit 0
}
main "$@"