Skip to content

Instantly share code, notes, and snippets.

@denschub
Last active August 6, 2018 16:28
Show Gist options
  • Save denschub/625f0b30af3ae58bc3f9f0f1bfc1df07 to your computer and use it in GitHub Desktop.
Save denschub/625f0b30af3ae58bc3f9f0f1bfc1df07 to your computer and use it in GitHub Desktop.
Extraction of my .zshrc: Function to start various Firefox versions with a (temporary) profile based on customizable templates.
#
# Starts Firefox with a temporary profile based on a template
#
# Assumes there is Firefox Nightly, DevEdition (Aurora), Beta, ESR and Stable
# installed on your OSX inside /Applications/, but adjustments are made easily.
#
# In my setup, I've got two templates in $PROFILE_ROOT/templates/ called
# "default" and "proxied". "proxied" is a copy of "default" with a local
# proxy set up that I use with mitmproxy.
#
# Usage:
# tmpfx [-k] [-n test] [-p] [-v stable|esr|beta|deved] -- [other Firefox arguments]
#
# Arguments:
# -k: if specified, the profile directory will not get deleted
# -n: uses the profile template specified
# -p: will use the "proxied" template
# -v: specifies the Firefox version to use. If unspecified, Nightly will
# get used. stable, beta and deved are valid names.
#
tmpfx() {
PROFILE_ROOT=~/Work/.firefox-profiles
OPTIND=1
KEEP_PROFILE=0
PROFILE="default"
FIREFOX_BINARY="/Applications/FirefoxNightly.app/Contents/MacOS/firefox"
while getopts "knpv:" opt; do
case "$opt" in
k)
KEEP_PROFILE=1
;;
n)
PROFILE=$OPTARG
;;
p)
PROFILE="proxied"
;;
v)
case "$OPTARG" in
stable)
FIREFOX_BINARY="/Applications/Firefox.app/Contents/MacOS/firefox"
;;
beta)
FIREFOX_BINARY="/Applications/FirefoxBeta.app/Contents/MacOS/firefox"
;;
deved)
FIREFOX_BINARY="/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox"
;;
esr)
FIREFOX_BINARY="/Applications/FirefoxESR.app/Contents/MacOS/firefox"
;;
*)
echo "Unrecognized firefox version: $OPTARG"
echo "Supported: none (nightly), deved, beta, stable, esr"
return 1
;;
esac
esac
done
SRC_PROFILE_DIR=$PROFILE_ROOT/templates/$PROFILE
if [ ! -d "$SRC_PROFILE_DIR" ]; then
echo "Profile template not found: $PROFILE"
return 1
fi
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
TMP_PROFILE_DIR=$(mktemp -d $PROFILE_ROOT/$PROFILE-XXXXXX)
cp -La $SRC_PROFILE_DIR/* $TMP_PROFILE_DIR
if [ "$KEEP_PROFILE" = 0 ]; then
function rmTmpProfile {
rm -rf $TMP_PROFILE_DIR
}
trap rmTmpProfile INT EXIT
fi
echo "Starting with $TMP_PROFILE_DIR"
$FIREFOX_BINARY --foreground --profile $TMP_PROFILE_DIR $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment