kindwolf.org Git repositories prooties / master bin / fx-profile-wrapper
master

Tree @master (Download .tar.gz)

fx-profile-wrapper @masterraw · history · blame

#!/bin/bash
# Copyright (c) 2016-2019 Xavier G. <xavier.prooties@kindwolf.org>
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law. You can redistribute it and/or modify it under
# the terms of the Do What The Fuck You Want To Public License, Version 2, as
# published by Sam Hocevar. See http://www.wtfpl.net/ for more details.

# This wrapper takes care of running Firefox/Iceweasel with:
#   - the adequate LOGNAME environment variable
#   - the adequate -profile argument
# All of this session crap is explained on 
# http://superuser.com/questions/119014/how-to-remotely-open-an-url-in-firefox-in-a-specific-profile

# This script is intended to be invoked with a custom name, typically via a
# symlink or a hardlink named firefox-<profile>, iceweasel-<profile>,
# icecat-<profile> or even KlaatuBaradaNikto-<profile> -- we are not really
# picky and will simply take whatever comes after the first dot (.) or dash
# (-) character.
invoked_name="$(basename "${0}")"
firefox_session="$(echo "${invoked_name}" | perl -nle 'print $1 if m#^(?:[^\.-]+)[\.-](.+)$#')"
echo "Asked to deal with session ${firefox_session}"

# Apply the "LOGNAME trick".
export LOGNAME="$(whoami).${firefox_session}"

# We are now ready to launch Firefox -- but wait, what should we invoke exactly?
# By default, invoke "firefox":
firefox_path='firefox'

# Let users override this through "configuration files":
generic_config_path="${HOME}/.config/fx-profile-wrapper/main.conf"
[ -f "${generic_config_path}" ] && source "${generic_config_path}"
specific_config_path="${HOME}/.config/fx-profile-wrapper/${invoked_name}.conf"
[ -f "${specific_config_path}" ] && source "${specific_config_path}"

# Let users override this again through an environment variable:
[ -n "${FIREFOX_PATH}" ] && firefox_path="${FIREFOX_PATH}"

# At last, launch that damn thing:
"${firefox_path}" ${firefox_extra_args} -profile ~/.mozilla/firefox/*${firefox_session} "$@"
# Users may also leverage firefox_extra_args to add arbitrary arguments, e.g.
# --please-dont-use-100-percent-CPU.