Add surfraw rofi extension to search the web with bangs

This commit is contained in:
Marty Oehme 2019-09-18 17:55:44 +02:00
parent 76efabe67b
commit 640ee9dbf9
4 changed files with 98 additions and 1 deletions

View file

@ -0,0 +1,5 @@
!aur - surfraw - duckduckgo !aur
!wp - surfraw - wikipedia
!rb - custom - https://www.rebuy.de/kaufen/suchen?q=
!sp - custom - http://www.sputnikmusic.com/search_results.php?genreid=0&search_in=Bands&search_text=
!hn - surfraw - duckduckgo !hackernews

View file

@ -0,0 +1,2 @@
default=duckduckgo
help_color="#0C73C2"

View file

@ -12,10 +12,14 @@ super + space
super + r super + r
exec rofi -modi combi,ssh -show combi -combi-modi "window,clipboard:greenclip print,run" exec rofi -modi combi,ssh -show combi -combi-modi "window,clipboard:greenclip print,run"
# open more extensive run menu # open gopass frontend menu
super + p super + p
exec rofi-gopass exec rofi-gopass
# open surfraw rofi frontend
super + q
exec rofi-surfraw
# System functionality # System functionality
# Enable lock screen (TODO does not stop music, etc yet # Enable lock screen (TODO does not stop music, etc yet

86
.local/bin/rofi-surfraw Executable file
View file

@ -0,0 +1,86 @@
#!/bin/bash
# source surfraw config
source $HOME/.surfraw.conf
# load global files
source /etc/rofi-surfraw.conf
# create local copy of custom searchengines
if [[ ! -d $HOME/.config/rofi-surfraw ]]; then
mkdir $HOME/.config/rofi-surfraw/searchengines
fi
if [[ ! -f $HOME/.config/rofi-surfraw/searchengines ]]; then
cp /usr/share/doc/rofi-surfraw/searchengines $HOME/.config/rofi-surfraw/searchengines
fi
# get local config
if [[ -f $HOME/.config/rofi-surfraw/config ]]; then
source $HOME/.config/rofi-surfraw/config
fi
# get list of search engines from surfraw
if [[ $@ == *"--no-list"* ]]; then
:
else
# list=$(sr -elvi | awk '{ print "?"$1 }' | tail -n +2)
list=$(sr -elvi | awk '{if (NR!=1) print "?"$1 }')
fi
# get custom engines from text file
if [[ $@ == *"--no-custom"* ]]; then
:
else
# custom=$(cat $HOME/.config/rofi-surfraw/searchengines | awk -F ' - ' '{ print $1 }')
custom=$(awk -F ' - ' '{ print $1 }' $HOME/.config/rofi-surfraw/searchengines)
fi
main () {
# Draw Menu
HELP_MSG="<span color=\"$help_color\">Hit Ctrl+Space to complete Engine Name
Searches without prepended engine use "${default}"</span>"
elvi=$(echo -e "${list}\n${custom}" | rofi -dmenu -mesg "${HELP_MSG}" -p "Search > ")
# Some logic
if [[ $elvi == "" ]]; then exit
elif [[ $elvi == "!"* ]]; then
entry=$(grep "$(echo "${elvi}" | awk '{ print $1 }')" "$HOME/.config/rofi-surfraw/searchengines")
method=$(echo "${entry}" | awk -F ' - ' '{ print $2 }')
bang=$(echo "${entry}" | awk -F ' - ' '{ print $3 }')
search=$(echo "${elvi}" | awk '{$1=""; print $0}' | cut -c 2-)
if [[ $method == "surfraw" ]]; then
sr ${bang} ${search}
elif [[ $method == "custom" ]]; then
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
fi
elif [[ $elvi == "?"* ]]; then
name=$(echo "${elvi}" | awk '{ print $1 }' | cut -c 2-)
search=$(echo "${elvi}" | awk '{$1=""; print $0}' | cut -c 2-)
sr ${name} ${search}
else
if [[ $default == "!"* ]]; then
entry=$(grep "$(echo "${default}" | awk '{ print $1 }')" "$HOME/.config/rofi-surfraw/searchengines")
method=$(echo "${entry}" | awk -F ' - ' '{ print $2 }')
bang=$(echo "${entry}" | awk -F ' - ' '{ print $3 }')
else
method="surfraw"
bang="$default"
fi
search="${elvi}"
if [[ $method == "surfraw" ]]; then
sr ${bang} ${search}
elif [[ $method == "custom" ]]; then
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
fi
fi
}
if [[ $1 == "--help" ]]; then
echo "rofi-surfraw - (C) 2015 Rasmus Steinke <rasi at xssn dot at>"
echo "---"
echo "--help this help"
echo "--no-list do not show inbuild search engines"
echo "--no-custom do not show custom search engines"
else
main
fi