Skip to content

Instantly share code, notes, and snippets.

@rogueai
Last active June 5, 2025 11:25
Show Gist options
  • Select an option

  • Save rogueai/8df7a751459d20b3dd646f182245e4ad to your computer and use it in GitHub Desktop.

Select an option

Save rogueai/8df7a751459d20b3dd646f182245e4ad to your computer and use it in GitHub Desktop.
Sway: switch firefox tab via Rofi menu

This script allows for switching to a firefox tab using Rofi from anywhere in Sway

rofi-tabs

Requirements

  1. mozeidon: the script works in conjunction wih Mozeidon, you'll need to follow the installation steps for the Firefox addon, Native Extension and CLI.
  2. jq: to parse mozeidon output
  3. sway: this might work on i3 as well, but I have not tested it

Rofi script

#!/bin/bash

sep="==@@@=="
# firefox executable, e.g.: firefox-developer-edition
firefox="firefox"
# mozeidon cli path
moz=$HOME/.local/bin/mozeidon
# rofi theme config
theme="$HOME/.config/rofi/theme.rasi"
# search engine query, used to perform a web search instead of switching tab
# when no tab is available
search_url="https://duckduckgo.com/?q="

# retrieve open tabs in the format: <windowId>:<tabId><sep><title>
tabs=$($moz tabs get | jq --arg sep "$sep" -r '.data[] | "\(.windowId):\(.id)\($sep)\(.title)"')
# get tab title to be displayed
tab=$(printf '%s\n' "${tabs[@]}" | awk -F"$sep" '{print $2}' | rofi -theme "$theme" -dmenu -i -p "🦊 Tab")
if [[ ! -z "$tab" ]]; then
	tab_id=$(printf '%s\n' "${tabs[@]}" | grep -F "$tab" | awk -F"$sep" '{print $1}')
	if [[ ! -z "$tab_id" ]]; then
    		# switch tab using mozeidon cli
		$moz tabs switch "$tab_id"
	else
		# if no tab is found, open a new search instead
		$moz tabs new "${search_url}${tab}"
	fi
	# focus firefox
	swaymsg "[app_id=\"$firefox\"]" focus
fi

Appendix: Mozeidon installation

Mozeidon is actually comprised of 3 different pieces of software working together:

  • Browser extension
  • Native app: download from releases
  • CLI: download from releases and place it in your $PATH

To enable the Native app to communicate with the extension, create a file $HOME/.mozilla/native-messaging-hosts/mozeidon.json with this content, making sure to replace path with your actual Native app path:

{
  "name": "mozeidon",
  "description": "Native messaging add-on to interact with your browser",
  "path": "/path/to/mozeidon-native-app",
  "type": "stdio",
  "allowed_extensions": [
    "mozeidon-addon@egovelox.com"
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment