#!/bin/bash # firefox-profile - pick a Firefox profile with rofi, one behind a password # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Pick a Firefox profile with rofi; one profile requires a password. # Hash file: printf '%s' 'secret' | sha256sum | cut -d' ' -f1 > ~/.config/firefox-profile.hash # ponytail: wrapper gate only, `firefox -P ` bypasses it. Encrypt the profile dir if that matters. PROTECTED="danix" HASHFILE="$HOME/.config/firefox-profile.hash" INI="$HOME/.mozilla/firefox/profiles.ini" # Opening a link with exactly one profile running: hand it to that instance, # no picker. The protected profile was already unlocked to get it running. if [ $# -gt 0 ]; then running=$(pgrep -af '^/usr/lib64/firefox/firefox(-bin)? (.* )?-P ' | sed -n 's/.* -P \([^ ]*\).*/\1/p' | sort -u) [ -n "$running" ] && [ "$(wc -l <<<"$running")" -eq 1 ] && exec firefox -P "$running" "$@" fi profile=$(sed -n 's/^Name=//p' "$INI" | rofi -dmenu -theme ~/.config/rofi/udt/list.rasi -i -p '󰈹 Firefox:') || exit 0 [ -n "$profile" ] || exit 0 if [ "$profile" = "$PROTECTED" ]; then pass=$(rofi -dmenu -theme ~/.config/rofi/udt/list.rasi -password -l 0 \ -mesg "Unlock Firefox profile: $profile" \ -theme-str 'mainbox { children: [ message, inputbar ]; padding: 16px; spacing: 8px; } message { background-color: transparent; padding: 0 0 4px 2px; } textbox { font: "Noto Sans Bold 13"; }' \ -theme-str 'entry { placeholder: "Password"; }' /dev/null)" ]; then notify-send "Firefox" "Wrong password" 2>/dev/null exit 1 fi fi exec firefox -P "$profile" "$@"