2020-09-12 15:41:12 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-09-18 15:55:44 +00:00
|
|
|
|
|
|
|
# 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
|
2020-09-12 15:41:12 +00:00
|
|
|
mkdir $HOME/.config/rofi-surfraw/searchengines
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
if [[ ! -f $HOME/.config/rofi-surfraw/searchengines ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
cp /usr/share/doc/rofi-surfraw/searchengines $HOME/.config/rofi-surfraw/searchengines
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# get local config
|
|
|
|
if [[ -f $HOME/.config/rofi-surfraw/config ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
source $HOME/.config/rofi-surfraw/config
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# get list of search engines from surfraw
|
|
|
|
if [[ $@ == *"--no-list"* ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
:
|
2019-09-18 15:55:44 +00:00
|
|
|
else
|
2020-09-12 15:41:12 +00:00
|
|
|
# list=$(sr -elvi | awk '{ print "?"$1 }' | tail -n +2)
|
|
|
|
list=$(sr -elvi | awk '{if (NR!=1) print "?"$1 }')
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# get custom engines from text file
|
|
|
|
if [[ $@ == *"--no-custom"* ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
:
|
2019-09-18 15:55:44 +00:00
|
|
|
else
|
2020-09-12 15:41:12 +00:00
|
|
|
# custom=$(cat $HOME/.config/rofi-surfraw/searchengines | awk -F ' - ' '{ print $1 }')
|
|
|
|
custom=$(awk -F ' - ' '{ print $1 }' $HOME/.config/rofi-surfraw/searchengines)
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
|
2020-09-12 15:41:12 +00:00
|
|
|
main() {
|
|
|
|
# Draw Menu
|
|
|
|
HELP_MSG="<span color=\"$help_color\">Hit Ctrl+Space to complete Engine Name
|
2019-09-18 15:55:44 +00:00
|
|
|
Searches without prepended engine use "${default}"</span>"
|
2020-09-12 15:41:12 +00:00
|
|
|
elvi=$(echo -e "${list}\n${custom}" | rofi -dmenu -mesg "${HELP_MSG}" -p "Search > ")
|
2019-09-18 15:55:44 +00:00
|
|
|
|
2020-09-12 15:41:12 +00:00
|
|
|
# Some logic
|
|
|
|
if [[ $elvi == "" ]]; then
|
|
|
|
exit
|
|
|
|
elif [[ $elvi == "!"* ]]; then
|
2019-09-18 15:55:44 +00:00
|
|
|
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
|
2020-09-12 15:41:12 +00:00
|
|
|
sr ${bang} ${search}
|
2019-09-18 15:55:44 +00:00
|
|
|
elif [[ $method == "custom" ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
2020-09-12 15:41:12 +00:00
|
|
|
elif [[ $elvi == "?"* ]]; then
|
2019-09-18 15:55:44 +00:00
|
|
|
name=$(echo "${elvi}" | awk '{ print $1 }' | cut -c 2-)
|
|
|
|
search=$(echo "${elvi}" | awk '{$1=""; print $0}' | cut -c 2-)
|
|
|
|
sr ${name} ${search}
|
2020-09-12 15:41:12 +00:00
|
|
|
else
|
2019-09-18 15:55:44 +00:00
|
|
|
if [[ $default == "!"* ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
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 }')
|
2019-09-18 15:55:44 +00:00
|
|
|
else
|
2020-09-12 15:41:12 +00:00
|
|
|
method="surfraw"
|
|
|
|
bang="$default"
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
|
|
|
search="${elvi}"
|
|
|
|
if [[ $method == "surfraw" ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
sr ${bang} ${search}
|
2019-09-18 15:55:44 +00:00
|
|
|
elif [[ $method == "custom" ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
"$SURFRAW_graphical_browser" $SURFRAW_graphical_browser_args ${bang}"${search}"
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|
2020-09-12 15:41:12 +00:00
|
|
|
fi
|
2019-09-18 15:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $1 == "--help" ]]; then
|
2020-09-12 15:41:12 +00:00
|
|
|
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"
|
2019-09-18 15:55:44 +00:00
|
|
|
else
|
2020-09-12 15:41:12 +00:00
|
|
|
main
|
2019-09-18 15:55:44 +00:00
|
|
|
fi
|