Last active
May 18, 2021 09:52
-
-
Save sk22/c227d61b32cf66854e6ad699139f3624 to your computer and use it in GitHub Desktop.
make firefox web app profiles based on profile "webapp.template" with installed firefox-gnome-theme (https://github.com/rafaelmardojai/firefox-gnome-theme)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROFILES=$HOME/.mozilla/firefox | |
TEMPLATE_DIR=$PROFILES/webapp.template | |
usage() { | |
cat << EOF | |
make-web-app | |
-n name (e.g. twitter, used as profile name and wm class webapp.twitter) | |
-t title (e.g. Twitter) | |
-i icon url (e.g. https://abs.twimg.com/.../icon-default-large.8e027b65.png) | |
-k keep old profile (false by default) | |
-c use custom user chrome (default: none) | |
EOF | |
echo profiles directory: | |
echo " " $PROFILES | |
cd $PROFILES | |
echo installed web apps: | |
echo " " webapp.* | |
cd $TEMPLATE_DIR/chrome/customChromes | |
echo custom chromes: | |
echo " " * | |
} | |
[ $# -eq 0 ] && usage && exit | |
while getopts "hn:t:i:c:k" opt; do | |
case $opt in | |
h) usage && exit | |
;; | |
n) APP_NAME="$OPTARG" | |
;; | |
t) APP_TITLE="$OPTARG" | |
;; | |
i) ICON_URL="$OPTARG" | |
;; | |
c) USER_CHROME="$OPTARG" | |
;; | |
k) KEEP_OLD_PROFILE=1 | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
PROFILE_NAME="webapp.$APP_NAME" | |
PROFILE_DIR=$PROFILES/$PROFILE_NAME | |
[ ! -z "$ICON_URL" ] && { | |
ICON_FILE="$HOME/.local/share/icons/$PROFILE_NAME.png" | |
if [ -f $ICON_URL ]; then | |
cp $ICON_URL $ICON_FILE | |
else | |
wget -O $ICON_FILE $ICON_URL | |
fi | |
} | |
! ((KEEP_OLD_PROFILE)) && [ -d $PROFILE_DIR ] && rm -rf $PROFILE_DIR | |
[ ! -d $PROFILE_DIR ] && { | |
cp -r $TEMPLATE_DIR $PROFILE_DIR | |
} | |
((KEEP_OLD_PROFILE)) || { | |
echo "please set your desired website as the home page" \ | |
"and optionally set up the search engine" | |
firefox --class $PROFILE_NAME --profile $PROFILE_DIR --no-remote \ | |
about:preferences#home | |
} | |
# remove old chrome | |
rm -rf $PROFILE_DIR/chrome/* | |
# link new chrome | |
ln -s $TEMPLATE_DIR/chrome/* $PROFILE_DIR/chrome | |
[ -n "$USER_CHROME" ] && { | |
cd $PROFILE_DIR/chrome | |
ln -s customChromes/$USER_CHROME.css customChrome.css | |
} | |
tee $HOME/.local/share/applications/$PROFILE_NAME.desktop << EOF | |
#!/usr/bin/env xdg-open | |
[Desktop Entry] | |
Version=1.0 | |
Name=$APP_TITLE | |
Description=Firefox web app for $APP_TITLE | |
Exec=firefox --class $PROFILE_NAME --profile $PROFILE_DIR --no-remote | |
StartupWMClass=$PROFILE_NAME | |
Icon=$PROFILE_NAME | |
Terminal=false | |
Type=Application | |
Categories=GTK;Network; | |
StartupNotify=true | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment