Instantly share code, notes, and snippets.

Embed
What would you like to do?
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