Skip to content

Instantly share code, notes, and snippets.

@andygock
Created November 12, 2015 10:12
Show Gist options
  • Save andygock/cd99f23e784f11b49330 to your computer and use it in GitHub Desktop.
Save andygock/cd99f23e784f11b49330 to your computer and use it in GitHub Desktop.
Bash shell script to set Firefox homepage
#!/bin/bash
# Script to change Firefox homepage in Linux
#
# Full path to 'profiles.ini'
PROFILES_INI=/home/$(whoami)/.mozilla/firefox/profiles.ini
if [ ! $1 ]; then
echo "Set URL as 1st argument"
exit 1
fi
if [ ! -f "$PROFILES_INI" ]; then
echo "Could not find profiles.ini:" $PROFILES_INI
exit 1
fi
# Assumes one Firefox profile
prefs_file=$(echo "${PROFILES_INI}" | sed 's/profiles.ini$//g')$(grep "Path=" "$PROFILES_INI" | sed 's/Path=//g')"/prefs.js"
if [ ! -f "$prefs_file" ]; then
echo "Could not find preferences file:" $prefs_file
exit 1
fi
echo "Editing prefs.js file:" $prefs_file
# Look for: user_pref("browser.startup.homepage", ".*");
sed -i "s/\(^user_pref(\"browser.startup.homepage\", \"\).*\(\");\)/\1${1}\2/g" "$prefs_file"
echo "Firefox homepage has been changed to:" $1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment