Skip to content

Commit a8d22a5

Browse files
authored
v0.6
- [X] _input() function : easy way to ask for an input. - [X] ask for input if no query was provided when searching - [X] handle mpv & vlc protocol
1 parent b21f605 commit a8d22a5

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# nbrowser
2+
3+
`nbrowser` started as browser prompter for Linux. It works by setting it as the default browser; any clicked links in non-browser apps are now sent to `nbrowser` where you are presented with a menu of all your installed browsers. You may now decide which app you’d like to continue opening the link with and more.
4+
25
<p align="center">
36
<img alt="screenshot" src="https://user-images.githubusercontent.com/73726132/136132026-aa2a685e-965c-44b5-b9c3-5a043dc2539a.gif">
47
rofi with DarkBlue theme

nbrowser

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# nbrowser v0.5
2+
# nbrowser v0.6
33
# author : odnar-dev <https://github.com/odnar-dev>
44
# source : https://github.com/MyOS-ArchLinux/nbrowser
55
# license: GPLv3 <https://gnu.org/licenses/gpl-3.0.html>
@@ -49,6 +49,10 @@ _choose(){
4949
rofi -dmenu -i -p 'Select Item ' -theme-str 'window {width: 95%;}' -l 10 -no-click-to-exit -filter "${@:-}"
5050
}
5151

52+
_input(){
53+
rofi -l 0 -width 50 -p "${@:-input}" -dmenu
54+
}
55+
5256
listfiles(){
5357
for file in ${NBROWSER_CONFIG_DIR}/$1/*; do
5458
[ -e "$file" ] || [ -L "$file" ] || continue
@@ -291,6 +295,9 @@ main(){
291295
freetube://*)
292296
open_video_with "${1:11}"
293297
;;
298+
mpv://*|vlc://*)
299+
open_video_with "${1:6}"
300+
;;
294301
play://*)
295302
open_video_with "${1:7}"
296303
;;
@@ -329,30 +336,34 @@ main(){
329336
"?"*)
330337
local engine="${1/?}"
331338
shift
339+
local searchquery="$*"
332340
if [ -f "${NBROWSER_CONFIG_DIR}/engines/${engine}" ] ; then
333341
source "${NBROWSER_CONFIG_DIR}/engines/${engine}"
334342
has nbrowser_search || _pemx "couldn't find nbrowser_search() function in ${NBROWSER_CONFIG_DIR}/engines/${engine}"
335-
[ -n "$1" ] && url_handler "$(nbrowser_search $*)"
343+
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
344+
[ -n "$searchquery" ] && url_handler "$(nbrowser_search $searchquery)"
336345
elif [ -n "${ENGINES[${engine:- }]}" ]; then
337-
url_handler "${ENGINES[$engine]}$*"
346+
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
347+
[ -n "$searchquery" ] && url_handler "${ENGINES[$engine]}$searchquery"
338348
elif [ -f "$NBROWSER_CONFIG_DIR/engines.json" ]; then
339-
local url=$(jq -r ".[]|select( .t == \"$engine\" )|.u" "$NBROWSER_CONFIG_DIR/engines.json" | sed "s/{{{s}}}/$*/g")
349+
local url=$(jq -r ".[]|select( .t == \"$engine\" )|.u" "$NBROWSER_CONFIG_DIR/engines.json")
340350
if [ ! -z "$url" ] ; then
341-
url_handler "$url"
351+
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
352+
[ -n "$searchquery" ] && url_handler "$(echo $url | sed "s/{{{s}}}/$searchquery/g")"
342353
else
343354
ENGINESLIST="$(listfiles engines)"
344355
ENGINESLIST+=" ${!ENGINES[@]}"
345356
ENGINESLIST+=" $(jq -r ".[]|.t" "$NBROWSER_CONFIG_DIR/engines.json")"
346357
engine=$(printf "%s\n" ${ENGINESLIST} | awk '!a[$0]++' | rofi -dmenu -p 'engines' -i -mesg "engine '${engine}' not found!")
347358
[ -z "$engine" ] && exit
348-
[ -n "$1" ] && main "?"$engine $*
359+
main "?"$engine $searchquery
349360
fi
350361
else
351362
ENGINESLIST="$(listfiles engines)"
352363
ENGINESLIST+=" ${!ENGINES[@]}"
353364
engine=$(printf "%s\n" ${ENGINESLIST} | awk '!a[$0]++' | rofi -dmenu -p 'engines' -i -mesg "engine '${engine}' not found!")
354365
[ -z "$engine" ] && exit
355-
[ -n "$1" ] && main "?"$engine $*
366+
main "?"$engine $searchquery
356367
fi
357368
;;
358369

0 commit comments

Comments
 (0)