scripts/firefox-quick-keywords/firefox-quick-keywords.sh
Guilherme Rugai Freire ea41b37b04
exclude all keywords starting with !
the reason for this is because I have a lot of keywords acting as search
engines inside firefox, such as arch packages search and macmillan
search. If I didnt filter those, the prompt would be flooded with
repetitive and nonsense items.
2022-01-30 02:47:22 -03:00

36 lines
867 B
Bash
Executable File

#!/bin/sh
if [ "$(command -v rofi)" ]; then
CMD='rofi -dmenu';
elif [ "$(command -v dmenu)" ]; then
CMD='dmenu';
else
echo 'Could not find either dmenu or rofi, exiting'
exit 1;
fi
# Copy the firefox database
DB='/tmp/places.sqlite'
cp ~/.mozilla/firefox/*.default-release/places.sqlite $DB
# SQL
QUERY="SELECT moz_keywords.keyword, moz_places.url FROM moz_keywords left JOIN moz_places ON place_id=moz_places.id WHERE moz_places.url<>'' AND moz_keywords.keyword<>''"
OPTIONS=$(sqlite3 $DB "$QUERY" | awk -F "|" '{print "["$1"] - "$NF}' | awk '! /^\[!.*$/')
# Clean tmp
rm $DB
# Prompt:
CHOICE=$(echo "$OPTIONS" | $CMD -p "Firefox quick open")
# Check choice
URL=$(echo "$CHOICE" | awk '{print $NF}') || exit 1
VALID=$(echo "$OPTIONS" | grep "$URL")
if [ -n "$VALID" ] && [ -n "$CHOICE" ]; then
firefox "$URL"
exit 0
else
exit 1
fi