Skip to content

Commit

Permalink
cleanup...
Browse files Browse the repository at this point in the history
  • Loading branch information
odnar-dev committed Sep 30, 2021
1 parent 2eec99c commit b58d057
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions nbrowser
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
# nbrowser v0.2
# author : odnar-dev <https://github.com/odnar-dev>
# source : https://github.com/MyOS-ArchLinux/nbrowser
# license: GPLv3+ <https://gnu.org/licenses/gpl.html>
# license: GPLv3 <https://gnu.org/licenses/gpl-3.0.html>
# shellcheck disable=SC2190,SC2086,SC1091

NBROWSER_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nbrowser"
NBROWSER_DEFAULT_SEARCH=${NBROWSER_DEFAULT_SEARCH:-duckduckgo}

declare -A ENGINES

ENGINES+=(["duckduckgo"]="https://duckduckgo.com/?q=")
ENGINES+=(["ddg"]="https://duckduckgo.com/?q=")
ENGINES+=(["google"]="https://www.google.com/search?q=")
ENGINES+=(["startpage"]="https://www.startpage.com/do/search?query=")

ENGINES+=(["archwiki"]="https://wiki.archlinux.org/index.php?title=Special:Search&search=")
ENGINES+=(["aur"]="https://aur.archlinux.org/packages/?O=0&SeB=nd&outdated=&SB=n&SO=a&PP=50&do_Search=Go&K=")

ENGINES+=(["git"]="https://github.com/search?q=")
ENGINES+=(["github"]="https://github.com/search?q=")

ENGINES+=(["mal"]="https://myanimelist.net/search/all?q=")
ENGINES+=(["imdb"]="https://www.imdb.com/find?q=")
ENGINES+=(["tmdb"]="https://www.themoviedb.org/search?query=")
ENGINES+=(["tvdb"]="https://www.thetvdb.com/search?query=")
ENGINES=(
["google"]="https://www.google.com/search?q="
["duckduckgo"]="https://duckduckgo.com/?q="
["ddg"]="https://duckduckgo.com/?q="
["startpage"]="https://www.startpage.com/do/search?query="
["archwiki"]="https://wiki.archlinux.org/index.php?title=Special:Search&search="
["aur"]="https://aur.archlinux.org/packages/?O=0&SeB=nd&outdated=&SB=n&SO=a&PP=50&do_Search=Go&K="
["github"]="https://github.com/search?q="
["git"]="https://github.com/search?q="
["imdb"]="https://www.imdb.com/find?q="
["tmdb"]="https://www.themoviedb.org/search?query="
["tvdb"]="https://www.thetvdb.com/search?query="
["mal"]="https://myanimelist.net/search/all?q="
)

has() {
case "$(command -v "$1" 2>/dev/null)" in
Expand Down Expand Up @@ -135,58 +134,65 @@ open_a_browser(){
{ setsid -f ${selected_browser} >/dev/null 2>&1 ; }
;;
esac

}

open_video_with(){
selected_action=$(printf '%s\n' "Play" "Download" "Open in Browser" | rofi -dmenu -p 'Open Video with' -mesg "${@//&/&amp;}" -i -l 3)

case "$selected_action" in
"Play")
if has 'play' ; then
{ setsid -f play "play://$*" >/dev/null 2>&1 ; }
else
if [ -n "${NBROWSER_PLAYER}" ] ; then
{ setsid -f ${NBROWSER_PLAYER} "$*" >/dev/null 2>&1 ; }
elif has 'mpv'; then
{ setsid -f mpv "$*" >/dev/null 2>&1 ; }
elif has 'vlc'; then
{ setsid -f vlc "$*" >/dev/null 2>&1 ; }
else
_pemx "mpv is not installed in your system!"
fi
;;
"Download")
if has 'dwld' ; then
{ setsid -f dwld "dwld://$*" >/dev/null 2>&1 ; }
if [ -n "${NBROWSER_DOWNLOADER}" ] ; then
{ setsid -f ${NBROWSER_DOWNLOADER} "$*" >/dev/null 2>&1 ; }
elif has 'youtube-dl'; then
{ setsid -f "${TERMINAL:-st}" -e sh -c "youtube-dl $* || read" >/dev/null 2>&1 ; }
elif has 'yt-dlp'; then
{ setsid -f "${TERMINAL:-st}" -e sh -c "yt-dlp $* || read" >/dev/null 2>&1 ; }
else
{ setsid -f "${TERMINAL:-st}" -e sh -c "youtube-dl $*" >/dev/null 2>&1 ; }
_pemx "youtube-dl is not installed in your system!"
fi
;;
"Open in Browser")
open_in_browser "$1"
;;
esac

}

open_picture_with(){
selected_action=$(printf '%s\n' "View" "Edit with Gimp" "Open in Browser" | rofi -dmenu -p 'Open Picture with' -mesg "${@//&/&amp;}" -i -l 3)

case "$selected_action" in
"View")
if has 'sxiv' ; then
if has 'sxiv'; then
curl -sL "$1" > "/tmp/$(echo "$@" | sed "s/.*\///;s/%20/ /g")" && \
{ setsid -f sxiv -a "/tmp/$(echo "$@" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ; }
elif has 'feh'; then
{ setsid -f feh "$*" >/dev/null 2>&1 ; }
else
_pemx "sxiv is no installed in your system!"
_pemx "sxiv is not installed in your system!"
fi
;;
"Edit with Gimp")
if has 'gimp' ; then
if has 'gimp'; then
{ setsid -f gimp "$*" >/dev/null 2>&1 ; }
else
_pemx "gimp is no installed in your system!"
_pemx "gimp is not installed in your system!"
fi
;;
"Open in Browser")
open_in_browser "$1"
;;
esac

}

open_in_browser(){
Expand All @@ -211,7 +217,6 @@ open_in_browser(){
{ setsid -f $selected_browser "$*" >/dev/null 2>&1 ; }
;;
esac

}

url_handler(){
Expand Down Expand Up @@ -296,7 +301,7 @@ main(){
# handle local pdf
[ -z "$NBROWSER_PDF_VIEWER" ] || installed_browsers[0]="PDF Reader : ${NBROWSER_PDF_VIEWER}"
;;
*.html)
*.html)
# handle local html
[ -z "$NBROWSER_HTML_EDITOR" ] || installed_browsers[0]="Text Editor : ${NBROWSER_HTML_EDITOR}"
esac
Expand Down

0 comments on commit b58d057

Please sign in to comment.