This script allows for switching to a firefox tab using Rofi from anywhere in Sway
mozeidon: the script works in conjunction wih Mozeidon, you'll need to follow the installation steps for the Firefox addon, Native Extension and CLI.jq: to parse mozeidon outputsway: this might work on i3 as well, but I have not tested it
#!/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
fiMozeidon 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"
]
}
