Skip to content

Instantly share code, notes, and snippets.

@reasonset
Created May 23, 2016 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reasonset/7a978e7cf2cf43eddc77ae0488e094cb to your computer and use it in GitHub Desktop.
Save reasonset/7a978e7cf2cf43eddc77ae0488e094cb to your computer and use it in GitHub Desktop.
Invoke latest Firefox with switching settings.
#!/bin/zsh --extended-glob
# If $1 == --profile
# use directory $2 instead".${profile_dir:-latest}"
if [[ $1 == --profile ]]
then
shift
profile_dir="$1"
shift
fi
print $profile_dir
# If .moziila is not for".${profile_dir:-latest}" Firefox.
# (#q:A) means expand symbolic link
if [[ -e ~/.mozilla && $( print ~/.mozilla(#q:A) ) != */.mozilla".${profile_dir:-latest}" ]]
then
# Abort if .mozilla is a directory
if [[ ! -h ~/.mozilla && -d ~/.mozilla ]]
then
print .mozilla is a directory. >&2
exit 1
fi
# Link .mozilla for".${profile_dir:-latest}" Firefox if any.
if [[ -e ~/.mozilla".${profile_dir:-latest}" ]]
then
[[ -h ~/.mozilla ]] && rm ~/.mozilla
ln -sf ~/.mozilla".${profile_dir:-latest}" ~/.mozilla
fi
fi
# Invoke".${profile_dir:-latest}" Firefox
~/lib/firefox/firefox "$@"
# If invoked with no .mozilla for".${profile_dir:-latest}" Firefox.
# Rename .mozilla for it.
if [[ ! -h ~/.mozilla ]]
then
mv ~/.mozilla ~/.mozilla".${profile_dir:-latest}"
fi
# Change link for original Firefox.
if [[ -e ~/.mozilla ]]
then
rm ~/.mozilla
fi
ln -s ~/.mozilla.orig ~/.mozilla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment