Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active November 28, 2015 01:54
Show Gist options
  • Select an option

  • Save sahal/e21c7b8e2fba2a27350d to your computer and use it in GitHub Desktop.

Select an option

Save sahal/e21c7b8e2fba2a27350d to your computer and use it in GitHub Desktop.
Create and remove temporary Firefox Profiles on the fly
#!/bin/sh
set -e
set -u
profname="Danger"
profloc="$(firefox --new-instance --CreateProfile "$profname" 2>&1 | sed -e s/.*$profname\'\ at\ \'// -e s/\'$//)"
profdir=$(dirname "$profloc")
profini=""$(dirname $profdir)"/profiles.ini"
tempout="$(mktemp)"
echo "$profloc"
echo "$profdir"
echo "$profini"
# start firefox
firefox -P "$profname" 2>&1 > /dev/null
#remove profile from disk
rm -rf "$profdir"
# remove profile from profiles.ini
# use sed's range feature to delete four ish lines
# http://www.theunixschool.com/2012/06/sed-25-examples-to-delete-line-or.html
#sed -in '/Name\=$profname/{s/.*//;x;d;};x;p;${x;p;}' $profini
#sed -in '/^Path\=.*\.$profname/{s/.*//;x;d;};x;p;${x;p;}' $profini
# do the same thing but read the file backwards ;)
tac $profini | sed '1,/e[^0]\]/d' | tac > $tempout
mv $tempout $profini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment