From c884ced6fca702f21c9c0811b6cc5998c4b196b7 Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Date: Sat, 31 Jul 2021 02:23:06 -0300 Subject: [PATCH 1/3] initial commit --- firefox-quick-keywords/LICENSE | 22 ++++++++++++ firefox-quick-keywords/README.md | 23 +++++++++++++ firefox-quick-keywords/firefox-quick-keywords | 34 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 firefox-quick-keywords/LICENSE create mode 100644 firefox-quick-keywords/README.md create mode 100755 firefox-quick-keywords/firefox-quick-keywords diff --git a/firefox-quick-keywords/LICENSE b/firefox-quick-keywords/LICENSE new file mode 100644 index 0000000..d586cfa --- /dev/null +++ b/firefox-quick-keywords/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2021 Guilherme Rugai Freire + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/firefox-quick-keywords/README.md b/firefox-quick-keywords/README.md new file mode 100644 index 0000000..f180ed9 --- /dev/null +++ b/firefox-quick-keywords/README.md @@ -0,0 +1,23 @@ +# Firefox Quick Keywords +dmenu or rofi launcher to open firefox bookmarks with keywords quickly + +## Installing firefox-quick-keywords + +> Requires [rofi](https://github.com/davatorium/rofi) or [dmenu](https://tools.suckless.org/dmenu/) + +```sh +git clone https://github.com/GRFreire/firefox-quick-keywords $HOME/.local/share/firefox-quick-keywords + +ln -s $HOME/.local/share/firefox-quick-keywords/firefox-quick-keywords $HOME/.local/bin/firefox-quick-keywords +``` + +After that, just run ```firefox-quick-keywords``` in your terminal + +## Update + +Go to ```$HOME/.local/share/firefox-quick-keywords``` and update the repo. + +```sh +cd $HOME/.local/share/firefox-quick-keywords +git pull +``` diff --git a/firefox-quick-keywords/firefox-quick-keywords b/firefox-quick-keywords/firefox-quick-keywords new file mode 100755 index 0000000..16b461c --- /dev/null +++ b/firefox-quick-keywords/firefox-quick-keywords @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +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 0; +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}') + +# Clean tmp +rm $DB + +# Prompt: +CHOICE=$(echo "$OPTIONS" | $CMD -p "Firefox quick open:") + +# Check choice +URL=$(echo "$CHOICE" | awk '{print $NF}') || exit +VALID=$(echo "$OPTIONS" | grep "$URL") +if [ -n "$VALID" ]; then + firefox $URL +else + exit 0 +fi \ No newline at end of file From b26330a3e97084193d2a522c68f0d57e0417fb69 Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Date: Sat, 31 Jul 2021 02:30:07 -0300 Subject: [PATCH 2/3] fix: firefox should not open with an empty choice --- firefox-quick-keywords/firefox-quick-keywords | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firefox-quick-keywords/firefox-quick-keywords b/firefox-quick-keywords/firefox-quick-keywords index 16b461c..ceb1c25 100755 --- a/firefox-quick-keywords/firefox-quick-keywords +++ b/firefox-quick-keywords/firefox-quick-keywords @@ -25,9 +25,9 @@ rm $DB CHOICE=$(echo "$OPTIONS" | $CMD -p "Firefox quick open:") # Check choice -URL=$(echo "$CHOICE" | awk '{print $NF}') || exit +URL=$(echo "$CHOICE" | awk '{print $NF}') || exit 0 VALID=$(echo "$OPTIONS" | grep "$URL") -if [ -n "$VALID" ]; then +if [ -n "$VALID" ] && [ -n "$CHOICE" ]; then firefox $URL else exit 0 From df446b740158484fcabe6c281ee2d29c86fc774d Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Date: Mon, 2 Aug 2021 12:12:26 -0300 Subject: [PATCH 3/3] clean up code --- firefox-quick-keywords/firefox-quick-keywords | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/firefox-quick-keywords/firefox-quick-keywords b/firefox-quick-keywords/firefox-quick-keywords index ceb1c25..a48de39 100755 --- a/firefox-quick-keywords/firefox-quick-keywords +++ b/firefox-quick-keywords/firefox-quick-keywords @@ -1,12 +1,12 @@ -#!/usr/bin/env bash +#!/bin/sh -if [[ $(command -v rofi) ]]; then +if [ "$(command -v rofi)" ]; then CMD='rofi -dmenu'; -elif [[ $(command -v dmenu) ]]; then +elif [ "$(command -v dmenu)" ]; then CMD='dmenu'; else echo 'Could not find either dmenu or rofi, exiting' - exit 0; + exit 1; fi @@ -25,10 +25,11 @@ rm $DB CHOICE=$(echo "$OPTIONS" | $CMD -p "Firefox quick open:") # Check choice -URL=$(echo "$CHOICE" | awk '{print $NF}') || exit 0 +URL=$(echo "$CHOICE" | awk '{print $NF}') || exit 1 VALID=$(echo "$OPTIONS" | grep "$URL") if [ -n "$VALID" ] && [ -n "$CHOICE" ]; then - firefox $URL -else + firefox "$URL" exit 0 -fi \ No newline at end of file +else + exit 1 +fi