Add rofi/bin/browsermenu

For opening URLs from Firefox/qutebrowser bookmarks or history.
This commit is contained in:
Henrik Lissner 2019-12-08 16:44:35 -05:00
parent 8d5dc2e4c2
commit 712e2ac58d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 85 additions and 1 deletions

60
config/rofi/bin/browsermenu Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env sh
# Interactively select (in skim) an url from Firefox/Chrome/Chromium history to
# open in your browser (depends on $BROWSER). Should work on Linux and MacOS.
#
# requires: sqlite3
ROFI_CMD='rofi -dmenu -theme theme/browsermenu.rasi -columns 1 -markup-rows -multi-select -p browser -i'
SEP=${1:-'{{::}}'}
_do_rofi() {
urls=$(awk -F "$SEP" '{printf "<b>%s</b>: <i>%s</i>\n", $1, $2}' | $ROFI_CMD | sed -e 's#&amp;#&#g' -e 's#&lt;#<#g' -e 's#&gt;#>#g')
IFS=$'\n'
for url in $urls; do
url=${url%</i>*}
url=${url##*<i>}
echo $url
done | xargs $BROWSER
}
case ${BROWSER:-firefox} in
firefox)
for dir in ~/.mozilla/firefox/*.default \
$XDG_CONFIG_HOME/firefox/.mozilla/firefox/*.default \
$XDG_DATA_HOME/mozilla/firefox/*.default \
~/Library/Application\ Support/Firefox/Profiles/*.default; do
if [[ -d "$dir" ]]; then
# The db can be locked from time to time. This is inefficient, but
# places.sqlite is usually under 30mb so this should be instant, and
# /tmp is cleared at boot so...
# if ! find /tmp/rofi-browsermenu -mmin +60 2>&1 >/dev/null; then
cp "$dir/places.sqlite" "/tmp/places.sqlite"
sqlite3 -separator $SEP "/tmp/places.sqlite" \
"SELECT DISTINCT title, url FROM moz_places \
WHERE title IS NOT NULL \
ORDER BY last_visit_date DESC" >/tmp/rofi-browsermenu
sqlite3 -separator $SEP "/tmp/places.sqlite" \
"SELECT DISTINCT mb.title, mp.url FROM moz_bookmarks mb \
INNER JOIN moz_places mp ON mp.id = mb.fk \
WHERE mb.type = 1 AND mb.title IS NOT NULL \
ORDER BY mp.frecency DESC \
LIMIT 200" >>/tmp/rofi-browsermenu
# fi
cat /tmp/rofi-browsermenu | sed -e 's#&#&amp;#g' -e 's#<#&lt;#g' -e 's#>#&gt;#g' | _do_rofi
break
fi
done
;;
qutebrowser)
{
sed -e 's/ /{{::}}/' urls | awk -F'{{::}}' '{printf "%s{{::}}%s\n", $2, $1}'
sqlite3 -separator $SEP "$XDG_DATA_HOME/qutebrowser/history.sqlite" \
"SELECT title, url FROM History \
WHERE title != '' \
GROUP BY url \
ORDER BY atime DESC"
} | _do_rofi
;;
*) rofi -e "No known browser" ;;
esac

View file

@ -5,9 +5,17 @@
systemPackages = with pkgs; [ systemPackages = with pkgs; [
(writeScriptBin "rofi" '' (writeScriptBin "rofi" ''
#!${stdenv.shell} #!${stdenv.shell}
exec ${rofi}/bin/rofi -terminal xst -m -1 $@ exec ${rofi}/bin/rofi -terminal xst -m -1 "$@"
'') '')
rofi rofi
(makeDesktopItem {
name = "browsermenu";
desktopName = "Open Bookmark in Firefox";
icon = "firefox";
exec = "/home/hlissner/.config/rofi/bin/browsermenu";
categories = "Network";
})
]; ];
# shellAliases = {}; # shellAliases = {};

View file

@ -0,0 +1,16 @@
/* -*- mode: css; -*- */
@import "appmenu.rasi"
#prompt {
background-color: #a9a1e1;
}
#entry {
text-color: #a9a1e1;
}
#element.selected {
text-color: #a9a1e1;
border-color: #a9a1e1;
}