Add rofi/bin/browsermenu
For opening URLs from Firefox/qutebrowser bookmarks or history.
This commit is contained in:
parent
8d5dc2e4c2
commit
712e2ac58d
60
config/rofi/bin/browsermenu
Executable file
60
config/rofi/bin/browsermenu
Executable 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#&#&#g' -e 's#<#<#g' -e 's#>#>#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#&#&#g' -e 's#<#<#g' -e 's#>#>#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
|
|
@ -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 = {};
|
||||||
|
|
16
themes/glimpse/rofi/browsermenu.rasi
Normal file
16
themes/glimpse/rofi/browsermenu.rasi
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue