22# nbrowser v0.2
33# author : odnar-dev <https://github.com/odnar-dev>
44# source : https://github.com/MyOS-ArchLinux/nbrowser
5- # license: GPLv3+ <https://gnu.org/licenses/gpl.html>
5+ # license: GPLv3 <https://gnu.org/licenses/gpl-3.0 .html>
66# shellcheck disable=SC2190,SC2086,SC1091
77
88NBROWSER_CONFIG_DIR=" ${XDG_CONFIG_HOME:- $HOME / .config} /nbrowser"
99NBROWSER_DEFAULT_SEARCH=${NBROWSER_DEFAULT_SEARCH:- duckduckgo}
1010
1111declare -A ENGINES
1212
13- ENGINES+=([" duckduckgo" ]=" https://duckduckgo.com/?q=" )
14- ENGINES+=([" ddg" ]=" https://duckduckgo.com/?q=" )
15- ENGINES+=([" google" ]=" https://www.google.com/search?q=" )
16- ENGINES+=([" startpage" ]=" https://www.startpage.com/do/search?query=" )
17-
18- ENGINES+=([" archwiki" ]=" https://wiki.archlinux.org/index.php?title=Special:Search&search=" )
19- ENGINES+=([" aur" ]=" https://aur.archlinux.org/packages/?O=0&SeB=nd&outdated=&SB=n&SO=a&PP=50&do_Search=Go&K=" )
20-
21- ENGINES+=([" git" ]=" https://github.com/search?q=" )
22- ENGINES+=([" github" ]=" https://github.com/search?q=" )
23-
24- ENGINES+=([" mal" ]=" https://myanimelist.net/search/all?q=" )
25- ENGINES+=([" imdb" ]=" https://www.imdb.com/find?q=" )
26- ENGINES+=([" tmdb" ]=" https://www.themoviedb.org/search?query=" )
27- ENGINES+=([" tvdb" ]=" https://www.thetvdb.com/search?query=" )
13+ ENGINES=(
14+ [" google" ]=" https://www.google.com/search?q="
15+ [" duckduckgo" ]=" https://duckduckgo.com/?q="
16+ [" ddg" ]=" https://duckduckgo.com/?q="
17+ [" startpage" ]=" https://www.startpage.com/do/search?query="
18+ [" archwiki" ]=" https://wiki.archlinux.org/index.php?title=Special:Search&search="
19+ [" aur" ]=" https://aur.archlinux.org/packages/?O=0&SeB=nd&outdated=&SB=n&SO=a&PP=50&do_Search=Go&K="
20+ [" github" ]=" https://github.com/search?q="
21+ [" git" ]=" https://github.com/search?q="
22+ [" imdb" ]=" https://www.imdb.com/find?q="
23+ [" tmdb" ]=" https://www.themoviedb.org/search?query="
24+ [" tvdb" ]=" https://www.thetvdb.com/search?query="
25+ [" mal" ]=" https://myanimelist.net/search/all?q="
26+ )
2827
2928has () {
3029 case " $( command -v " $1 " 2> /dev/null) " in
@@ -135,58 +134,65 @@ open_a_browser(){
135134 { setsid -f ${selected_browser} > /dev/null 2>&1 ; }
136135 ;;
137136 esac
138-
139137}
140138
141139open_video_with (){
142140 selected_action=$( printf ' %s\n' " Play" " Download" " Open in Browser" | rofi -dmenu -p ' Open Video with' -mesg " ${@// &/ &} " -i -l 3)
143141
144142 case " $selected_action " in
145143 " Play" )
146- if has ' play ' ; then
147- { setsid -f play " play:// $* " > /dev/null 2>&1 ; }
148- else
144+ if [ -n " ${NBROWSER_PLAYER} " ] ; then
145+ { setsid -f ${NBROWSER_PLAYER} " $* " > /dev/null 2>&1 ; }
146+ elif has ' mpv ' ; then
149147 { setsid -f mpv " $* " > /dev/null 2>&1 ; }
148+ elif has ' vlc' ; then
149+ { setsid -f vlc " $* " > /dev/null 2>&1 ; }
150+ else
151+ _pemx " mpv is not installed in your system!"
150152 fi
151153 ;;
152154 " Download" )
153- if has ' dwld' ; then
154- { setsid -f dwld " dwld://$* " > /dev/null 2>&1 ; }
155+ if [ -n " ${NBROWSER_DOWNLOADER} " ] ; then
156+ { setsid -f ${NBROWSER_DOWNLOADER} " $* " > /dev/null 2>&1 ; }
157+ elif has ' youtube-dl' ; then
158+ { setsid -f " ${TERMINAL:- st} " -e sh -c " youtube-dl $* || read" > /dev/null 2>&1 ; }
159+ elif has ' yt-dlp' ; then
160+ { setsid -f " ${TERMINAL:- st} " -e sh -c " yt-dlp $* || read" > /dev/null 2>&1 ; }
155161 else
156- { setsid -f " ${TERMINAL :- st} " -e sh -c " youtube-dl $* " > /dev/null 2>&1 ; }
162+ _pemx " youtube-dl is not installed in your system! "
157163 fi
158164 ;;
159165 " Open in Browser" )
160166 open_in_browser " $1 "
161167 ;;
162168 esac
163-
164169}
165170
166171open_picture_with (){
167172 selected_action=$( printf ' %s\n' " View" " Edit with Gimp" " Open in Browser" | rofi -dmenu -p ' Open Picture with' -mesg " ${@// &/ &} " -i -l 3)
168173
169174 case " $selected_action " in
170175 " View" )
171- if has ' sxiv' ; then
176+ if has ' sxiv' ; then
172177 curl -sL " $1 " > " /tmp/$( echo " $@ " | sed " s/.*\///;s/%20/ /g" ) " && \
173178 { setsid -f sxiv -a " /tmp/$( echo " $@ " | sed " s/.*\///;s/%20/ /g" ) " > /dev/null 2>&1 ; }
179+ elif has ' feh' ; then
180+ { setsid -f feh " $* " > /dev/null 2>&1 ; }
174181 else
175- _pemx " sxiv is no installed in your system!"
182+ _pemx " sxiv is not installed in your system!"
176183 fi
177184 ;;
178185 " Edit with Gimp" )
179- if has ' gimp' ; then
186+ if has ' gimp' ; then
180187 { setsid -f gimp " $* " > /dev/null 2>&1 ; }
181188 else
182- _pemx " gimp is no installed in your system!"
189+ _pemx " gimp is not installed in your system!"
183190 fi
184191 ;;
185192 " Open in Browser" )
186193 open_in_browser " $1 "
187194 ;;
188195 esac
189-
190196}
191197
192198open_in_browser (){
@@ -211,7 +217,6 @@ open_in_browser(){
211217 { setsid -f $selected_browser " $* " > /dev/null 2>&1 ; }
212218 ;;
213219 esac
214-
215220}
216221
217222url_handler (){
@@ -296,7 +301,7 @@ main(){
296301 # handle local pdf
297302 [ -z " $NBROWSER_PDF_VIEWER " ] || installed_browsers[0]=" PDF Reader : ${NBROWSER_PDF_VIEWER} "
298303 ;;
299- * .html)
304+ * .html)
300305 # handle local html
301306 [ -z " $NBROWSER_HTML_EDITOR " ] || installed_browsers[0]=" Text Editor : ${NBROWSER_HTML_EDITOR} "
302307 esac
0 commit comments