Skip to content

Commit

Permalink
v0.6
Browse files Browse the repository at this point in the history
- [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
  • Loading branch information
odnar-dev authored Mar 17, 2022
1 parent b21f605 commit a8d22a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# nbrowser

`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.

<p align="center">
<img alt="screenshot" src="https://user-images.githubusercontent.com/73726132/136132026-aa2a685e-965c-44b5-b9c3-5a043dc2539a.gif">
rofi with DarkBlue theme
Expand Down
25 changes: 18 additions & 7 deletions nbrowser
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# nbrowser v0.5
# nbrowser v0.6
# author : odnar-dev <https://github.com/odnar-dev>
# source : https://github.com/MyOS-ArchLinux/nbrowser
# license: GPLv3 <https://gnu.org/licenses/gpl-3.0.html>
Expand Down Expand Up @@ -49,6 +49,10 @@ _choose(){
rofi -dmenu -i -p 'Select Item ' -theme-str 'window {width: 95%;}' -l 10 -no-click-to-exit -filter "${@:-}"
}

_input(){
rofi -l 0 -width 50 -p "${@:-input}" -dmenu
}

listfiles(){
for file in ${NBROWSER_CONFIG_DIR}/$1/*; do
[ -e "$file" ] || [ -L "$file" ] || continue
Expand Down Expand Up @@ -291,6 +295,9 @@ main(){
freetube://*)
open_video_with "${1:11}"
;;
mpv://*|vlc://*)
open_video_with "${1:6}"
;;
play://*)
open_video_with "${1:7}"
;;
Expand Down Expand Up @@ -329,30 +336,34 @@ main(){
"?"*)
local engine="${1/?}"
shift
local searchquery="$*"
if [ -f "${NBROWSER_CONFIG_DIR}/engines/${engine}" ] ; then
source "${NBROWSER_CONFIG_DIR}/engines/${engine}"
has nbrowser_search || _pemx "couldn't find nbrowser_search() function in ${NBROWSER_CONFIG_DIR}/engines/${engine}"
[ -n "$1" ] && url_handler "$(nbrowser_search $*)"
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
[ -n "$searchquery" ] && url_handler "$(nbrowser_search $searchquery)"
elif [ -n "${ENGINES[${engine:- }]}" ]; then
url_handler "${ENGINES[$engine]}$*"
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
[ -n "$searchquery" ] && url_handler "${ENGINES[$engine]}$searchquery"
elif [ -f "$NBROWSER_CONFIG_DIR/engines.json" ]; then
local url=$(jq -r ".[]|select( .t == \"$engine\" )|.u" "$NBROWSER_CONFIG_DIR/engines.json" | sed "s/{{{s}}}/$*/g")
local url=$(jq -r ".[]|select( .t == \"$engine\" )|.u" "$NBROWSER_CONFIG_DIR/engines.json")
if [ ! -z "$url" ] ; then
url_handler "$url"
[ -z "$searchquery" ] && searchquery=$(_input "$engine Search")
[ -n "$searchquery" ] && url_handler "$(echo $url | sed "s/{{{s}}}/$searchquery/g")"
else
ENGINESLIST="$(listfiles engines)"
ENGINESLIST+=" ${!ENGINES[@]}"
ENGINESLIST+=" $(jq -r ".[]|.t" "$NBROWSER_CONFIG_DIR/engines.json")"
engine=$(printf "%s\n" ${ENGINESLIST} | awk '!a[$0]++' | rofi -dmenu -p 'engines' -i -mesg "engine '${engine}' not found!")
[ -z "$engine" ] && exit
[ -n "$1" ] && main "?"$engine $*
main "?"$engine $searchquery
fi
else
ENGINESLIST="$(listfiles engines)"
ENGINESLIST+=" ${!ENGINES[@]}"
engine=$(printf "%s\n" ${ENGINESLIST} | awk '!a[$0]++' | rofi -dmenu -p 'engines' -i -mesg "engine '${engine}' not found!")
[ -z "$engine" ] && exit
[ -n "$1" ] && main "?"$engine $*
main "?"$engine $searchquery
fi
;;

Expand Down

0 comments on commit a8d22a5

Please # to comment.