diff options
Diffstat (limited to 'mac/.local/bin/browserprofile')
| -rwxr-xr-x | mac/.local/bin/browserprofile | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/mac/.local/bin/browserprofile b/mac/.local/bin/browserprofile new file mode 100755 index 0000000..c66f183 --- /dev/null +++ b/mac/.local/bin/browserprofile @@ -0,0 +1,108 @@ +#!/bin/sh + +# Define the profile paths +work_profile="$USER.work" +home_profile="$USER.default" +tmux_profile="$USER.tmux" + +usage() { + echo "Update the default profile in profiles.ini for Firefox or Librewolf." + echo "" + echo "Usage: ${0##*/} <browser> [<profile_type>]" + echo "" + echo "Options:" + echo " -h : Show this help message." + echo " <browser> : The browser to configure." + echo " Accepted values:" + echo " -f/firefox" + echo " -l/librewolf" + echo " <profile_type> : (Optional) If not specified, the default profile will be used." + echo " Accepted values:" + echo " work: Sets the work profile ($work_profile)" + echo " default: Sets the home profile ($home_profile)" + echo " tmux: Sets the home profile ($tmux_profile)" + echo "" + echo "Examples:" + echo " ${0##*/} -f -w # Set the work profile for Firefox" + echo " ${0##*/} -l -d # Set the default profile for Librewolf" + echo " ${0##*/} -f -d # Set the default profile for Firefox" + echo " ${0##*/} -f -t # Set the tmux profile for Firefox" +} + +update_profiles_ini() { + case "$1" in + -f | --firefox | firefox) profiles_ini_path="$HOME/.mozilla/firefox/profiles.ini" ;; + -l | --librewolf | librewolf) profiles_ini_path="$HOME/.librewolf/profiles.ini" ;; + *) + echo "Invalid browser type. Please use 'firefox' or 'librewolf'." + return 1 + ;; + esac + + profile_to_set=$2 + + # Backup current profiles.ini + cp "$profiles_ini_path" "$profiles_ini_path.bak" + + # Update the profiles.ini + awk -v profile="$profile_to_set" ' + /^\[Install/ { + print + found=1 + next + } + found && /^Default=/ { + sub(/=.*/, "=" profile) + print + next + } + { + print + }' "$profiles_ini_path" >"$profiles_ini_path.tmp" && mv "$profiles_ini_path.tmp" "$profiles_ini_path" + + echo "Updated profiles.ini to use profile: $profile_to_set" +} + +# Main function +update_profile() { + browser=$1 + profile_type=$2 + + # Check if a browser is provided + if [ -z "$browser" ]; then + usage && exit 1 + fi + + # Convert profile_type to lowercase for case-insensitive comparison + if [ -n "$profile_type" ]; then + profile_type=$(echo "$profile_type" | tr '[:upper:]' '[:lower:]') + else + # Set to "default" if profile_type is not given + profile_type="default" + fi + + # Set the profile based on the input + case "$profile_type" in + -w | --work | work) + update_profiles_ini "$browser" "$work_profile" + ;; + -d | --default | default) + update_profiles_ini "$browser" "$home_profile" + ;; + -t | --tmux | tmux) + update_profiles_ini "$browser" "$tmux_profile" + ;; + *) + echo "Invalid profile type. Please use 'work' or 'default'." + return 1 + ;; + esac +} + +# Check for help flag +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + usage && exit 0 +fi + +# Execute the main function with arguments passed to the script +update_profile "$1" "$2" |
