Created
October 16, 2019 21:34
-
-
Save fidergo-stephane-gourichon/b1dd95c6ad88d868a59a119fa9380caa to your computer and use it in GitHub Desktop.
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
echo {} /* >/dev/null SG\MARKER\VERY\IMPROBABLE\STRING\MY\START | |
# This file is both a valid CSS style sheet, | |
# and a valid bash script. | |
# It adjusts your main Firefox profile so that github and all the | |
# stackexchange websites do not artifically limit main area width. | |
# Hooray! No more clobbered listings! | |
# More technically, it configures and enables userContent.css. It | |
# will preserve pre-existing content of that file and add itself at | |
# the beginning. | |
# You can even run it again in your profile directory to update the | |
# list of stackexchange websites: | |
# bash firefox_profile_relax_github_stackexchange_column_width.sh | |
# It requires curl and basic POSIX tools. May not work on BSD and thus Mac OS X but should be relatively easy to fix. | |
# If you don't have realpath or readlink, you may get a portable | |
# variant on | |
# https://github.com/mkropat/sh-realpath/blob/master/realpath.sh | |
set -eu | |
THIS_FILE="${BASH_SOURCE[0]}" | |
# find_firefox_profile() | |
{ | |
# Based on https://askubuntu.com/questions/239543/get-the-default-firefox-profile-directory-from-bash | |
cd ~/.mozilla/firefox/ && if [[ $(grep '\[Profile[^0]\]' profiles.ini) ]] | |
then FFPROFILE="$PWD/$(sed -E -n '/^Default=/{s/^Default=(.*)$/\1/p;q}' profiles.ini)" | |
else FFPROFILE="$PWD/$(grep 'Path=' profiles.ini | sed 's/^Path=//')" | |
fi | |
cd "$OLDPWD" | |
} | |
echo >&2 "Firefox profile found in: ${FFPROFILE}" | |
[[ -d "${FFPROFILE}/chrome" ]] || mkdir "${FFPROFILE}/chrome" | |
TARGET="${FFPROFILE}/chrome/userContent.css" | |
ALL_STACKEXCHANGE_DOMAINS="" | |
while read -u 4 DOMAIN | |
do | |
ALL_STACKEXCHANGE_DOMAINS="$ALL_STACKEXCHANGE_DOMAINS domain($DOMAIN)," | |
done 4< <( if ! [[ -r stackexchange_sites.html ]] | |
then curl https://stackexchange.com/sites >|stackexchange_sites.html | |
fi | |
sed <stackexchange_sites.html -n 's|^.*<a href="https://\([^"]*\)" class="noscript-link.*$|\1|p' ) | |
ALL_STACKEXCHANGE_DOMAINS="$ALL_STACKEXCHANGE_DOMAINS domain\(SG_MARKER_VERY_IMPROBABLE_STRING_ALLSTACKEXCHANGEDOMAINS\)" | |
{ | |
# Insert our part first. | |
sed '/SG\\MARKER\\VERY\\IMPROBABLE\\STRING\\BASH\\START/,/SG\\MARKER\\VERY\\IMPROBABLE\\STRING\\BASH\\END/d' <"${THIS_FILE}" | | |
sed -E "s/^.*\(SG_MARKER_VERY_IMPROBABLE_STRING_ALLSTACKEXCHANGEDOMAINS\)$/@-moz-document $ALL_STACKEXCHANGE_DOMAINS/" | |
# Preserve original file content, removing all our part. | |
[[ -f "${TARGET}" ]] && sed '/SG\\MARKER\\VERY\\IMPROBABLE\\STRING\\MY\\START/,/SG\\MARKER\\VERY\\IMPROBABLE\\STRING\\MY\\END/d' <"${TARGET}" | |
} > ${TARGET}.tmp | |
mv -vf ${TARGET}.tmp ${TARGET} | |
echo 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' >>"${FFPROFILE}/prefs.js" | |
# If firefox is active, the customzation above will be lost when it closes. | |
if [[ -L "${FFPROFILE}/lock" ]] | |
then | |
# Yes, there is a race condition. Let's accept is on the basis of | |
# the Buridan's_principle | |
# https://en.wikipedia.org/wiki/Buridan's_ass#Buridan's_principle | |
echo -n >&2 "Warning: firefox appears to be active. Waiting of it to stop." | |
while [[ -L "${FFPROFILE}/lock" ]] | |
do | |
echo >&2 -n . | |
sleep 1 | |
done | |
echo >&2 "Okay!" | |
fi | |
echo 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' >>"${FFPROFILE}/prefs.js" | |
echo >&2 "Firefox profile configured to honor userContent.css." | |
exit 0 | |
Bash ended. Now switch to CSS part. | |
SG\MARKER\VERY\IMPROBABLE\STRING\BASH\END */ | |
@namespace url(http://www.w3.org/1999/xhtml); | |
/* Don't limit width on github.com */ | |
@-moz-document domain(github.com) | |
{ | |
.container-lg { | |
max-width: 100% !important; | |
} | |
} | |
/* Don't limit width on StackExchange sites. */ | |
@-moz-document domain(SG_MARKER_VERY_IMPROBABLE_STRING_ALLSTACKEXCHANGEDOMAINS) | |
{ | |
#content { | |
max-width: 100% !important; | |
width: 100% !important; | |
} | |
#content { | |
width: 100% !important; | |
} | |
body > .container { | |
max-width: 100% !important; | |
} | |
} | |
/* SG\MARKER\VERY\IMPROBABLE\STRING\MY\END */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment