Skip to main content

Quick launcher with firefox tabs: rofi + brotab

 I've been using quick launchers like kupfer or ulauncher for a while, but I needed to switch to something else because kupfer tends to crash from time to time (Ubuntu 20.04) and ulauncher is a memory hog with lots of plugins (https://github.com/Ulauncher/Ulauncher/issues/590).


I've looked around and rofi looks like a great little launcher - with the added bonus that it runs only when you launch it (it's not resident in memory).


For best features it should be installed from git, not apt (instructions here: https://github.com/davatorium/rofi/blob/next/INSTALL.md). First prepare the build environment. You'll need to enable deb-src in your /etc/apt/sources.list for this to work. Make sure you have the correct distribution (in case you did a do-release-upgrade you may have wrong deb-src entries commented out): https://unix.stackexchange.com/questions/537537/how-to-put-some-source-uris-in-your-sources-list

sudo apt-get build-dep rofi
git clone https://github.com/davatorium/rofi
cd rofi
git submodule update --init
autoreconf -i
mkdir build && cd build
../configure --disable-check
make
sudo make install
Now you can test it out by running a command such as this:
rofi -combi-modi window,drun,run,ssh -theme gruvbox-dark-hard -font "hack 10" -show combi -icon-theme "Papirus" -show-icons

You should see a window like in the screenshot


Now, how about adding Firefox tab support? There is a project for it here https://gitlab.com/ddl37.nz/rofi-firefox-tabs, but I couldn't get it to work (the server part).
So, I tired brotab integration. Brotab is a project that exposes (and allows you to switch to) Firefox tabs from the CLI (https://pypi.org/project/brotab/).
Install it with:

 sudo pip3 install brotab
 

It also needs a Firefox (or Chrome, or Brave) extension to be installed in the browser side: https://addons.mozilla.org/en-US/firefox/addon/brotab/
Once you install and enable the extension you should be able to see a listing of your open tabs by running 

brotab list

There is an integration example between rofi and brotab over at brotab's github page: https://github.com/balta2ar/brotab/issues/5 and we'll try to implement it.

Copy the lua code from this post https://github.com/balta2ar/brotab/issues/5#issuecomment-631165782 to ~/.config/brotab_modi.lua:

$ cat ~/.config/brotab_modi.lua 
#!/usr/bin/lua

local bp = require("lua-shepi")
local rofi_markup = print("\0markup-rows\x1ftrue\n")

local function GetTabs(sin, sout, serr)
local delim = print("\x00delim\x1f\x0f")
local markup_s = '%s\n<span foreground="#6B838E">%s\n</span><span foreground="#44555D"><small><i>%s</i></small></span>\x0f'
local pipe_in = sin:read("a")
for line in pipe_in:gmatch("([^\n]*)\n") do
local id, title, url = line:match("([^\t]+)\t([^\t]+)\t([^\t]+)")
local result = string.format(markup_s, title, url:match("https?://[www%.]*(.*)"), id)
local prune_s = result:gsub("&", "&amp;")
sout:write(prune_s)
end
end

args = {...}
local pipe = bp.bt("list") | bp.tac("-s", "\n") | bp.fun(GetTabs)
if not args[1] then
io.write(pipe())
else
os.execute(string.format("bt activate %s", args[1]:match("<i>(.-)</i>")))
end

You will need to install lua and lua-shepi packages:
sudo apt-get install lua5.3 lua5.3-dev luarocks
sudo luarocks install lua-shepi
 Now you can try to run rofi to list your tabs (adjust for the file path):
rofi -modi brotab:/home/$USER/.config/brotab_modi.lua -show brotab

Now, we need to combine the brotab functionality with all the other rofi features. Let's try this command:

rofi -combi-modi window,brotab:/home/$USER/.config/brotab_modi.lua,drun,ssh,run -theme gruvbox-dark-hard -font "hack 10" -show combi -icon-theme "Papirus" -show-icons

Now you can search through open windows, open tabs, menu entries, programs and ssh entries and quickly launch them. We can save the configuration to a file and bind rofi to a key combination, so that it will be launched on demand:

mkdir ~/.config/rofi

rofi -combi-modi window,brotab:/home/$USER/.config/brotab_modi.lua,drun,ssh,run -theme gruvbox-dark-hard -font "hack 10" -show combi -icon-theme "Papirus" -show-icons -dump-config > ~/.config/rofi/config.rasi


You can bind it to any key combination you like. I use Win+Space. In XFCE go to Settings Manager -> Keyboard -> Application Shortcuts and add a new shortcut. The command to run is just:

rofi -show combi


Comments

Popular posts from this blog

Home Assistant + Android TV = fun

Here's a quick setup guide for controlling your Android TV from within Home Assistant. I've used it to control a genuine Android TV (Philips 7304) and an Odroid N2 running Android TV. For this to work you need ADB access. It can usually be enabled from within Developer Settings. The great part is - you don't need root access! The most important things are described in the androidtv component for Home Assistant: https://www.home-assistant.io/integrations/androidtv/ Make sure you go through the adb setup. My configuration is simple (inside configuration.yaml): media_player:   - platform: androidtv     name: TV Bedroom ATV     host: 192.168.1.61     device_class: androidtv Once Home Assistant restarts, your TV might require you to accept the connection (adb authentication). This happens only once (or until you reset your ATV to factory settings). Once running the integration will show you the current ATV state (on or off) and allows you to turn it on or off.

SmokePing + InfluxDB export + docker + slaves + Grafana = fun

I've been working for a while on this project - with the purpose of getting SmokePing measurements from different hosts (slaves) into InfluxDB so that we can better graph them with Grafana. The slaves run multiple Smokeping instances inside Docker so that they have separate networking (measure through different uplinks, independently). This will not be a comprehensive configuration guide, but a quick "how to" to handle setup and basic troubleshooting. It assumes you already know how to set up and operate a regular Smokeping install with or without slaves and that you are fluent in Smokeping configuration syntax, know your way around Docker and aren't a stranger from InfluxDB and Grafana (sorry, there's a lot of information to take in). 1. Getting Smokeping with InfluxDB support - you can get it either from the official page (most changes have been merged) - https://github.com/oetiker/SmokePing (PR discussion here: https://github.com/oetiker/SmokePing/issues/

Installing Home Assistant Supervised on an old 32bit HP laptop

 I've received a challenge from my former boss: an old HP laptop that was born in 2005:  an HP-Compaq NC6220 ( https://www.pocket-lint.com/laptops/reviews/hp/68181-hp-compaq-nc6220-notebook-laptop/ ). The specs are abysmal: So, i386, 1.7GHz single-core CPU (remember those?), 1G of DDR2 RAM (2x512M) and a 40GB ATA (not SATA!) drive. But hey, at least it has a serial port!  The challenge is to install HomeAssistant ( https://www.home-assistant.io/ ) on it so that he can monitor some Zigbee temperature sensors and relays (via a gateway). The first hurdle was to remove the BIOS password - following this nice guide: https://www.youtube.com/watch?v=ZaGKyb0ntSg Next-up - install HASSOS. Unfortunately, it doesn't support i386, but only x86_64... So, I went the Home Assistant Supervised route, and installed Debian 11 i386 edition from a netinstall USB ( https://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-11.6.0-i386-netinst.iso ).   Once Debian was up and running (didn't