Last active
August 9, 2022 21:30
-
-
Save illia-danko/6cebbc61eaf427438a57ff90b30ad2bb to your computer and use it in GitHub Desktop.
Change font of gnome-shell globally
This file contains 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
#!/usr/bin/env bash | |
# | |
# Author: Elijah Danko (me@elijahdanko.net) | |
# License: MIT | |
# | |
# Change font on Adwaita gnome-shell theme using gresource. | |
# You can adapt the script to adjust whatever you want. | |
# | |
# Tested on archlinux gnome-shell 3.34.2. | |
# Make sure that `gresource` and `glib-compile-resources` are located in the path. | |
# | |
# Usage: bash gnome-shell-set-font.sh <font> | |
set -euo pipefail | |
if [[ "$#" -ne 1 ]]; then 1>&2 echo "Font should be specified."; exit 1; fi | |
# Check requirements. | |
for cmd in \ | |
gresource \ | |
glib-compile-resources; | |
do | |
if [[ ! $(command -v "$cmd") ]]; then | |
1>&2 echo "$cmd not found in the path."; exit 1 | |
fi | |
done | |
# Extract gresources. | |
font_name="$1" | |
build_dir="$(readlink -f $(dirname "${BASH_SOURCE[0]}"))/build" | |
gst_path="/usr/share/gnome-shell" | |
gst="$gst_path/gnome-shell-theme.gresource" | |
gst_curr="$gst" | |
if [[ -f "$gst.ORIG" ]]; then gst_curr="$gst.ORIG"; fi | |
theme_path="$build_dir/org/gnome/shell/theme" | |
rm -rf "$build_dir" | |
mkdir -p "$theme_path" | |
for src in `gresource list $gst_curr`; do | |
mkdir -p "$build_dir/$(dirname $src)" | |
gresource extract $gst_curr $src > "$build_dir$src" | |
done | |
# Add new font. | |
find "$build_dir" -type f -name "*.css" | xargs sed -i -e "s/font-family:/font-family: $font_name,/g" | |
all_resources=$(find "$theme_path" -type f -printf " <file>%P</file>\n") | |
cat <<EOF > "$theme_path/gnome-shell-theme.gresource.xml" | |
<?xml version="1.0" encoding="UTF-8"?> | |
<gresources> | |
<gresource prefix="/org/gnome/shell/theme"> | |
$all_resources | |
</gresource> | |
</gresources> | |
EOF | |
# Compile and copy back. | |
pushd "$(pwd)" 1>/dev/null | |
cd "$theme_path" | |
glib-compile-resources gnome-shell-theme.gresource.xml | |
# Backup the original resource. | |
if [[ ! -f "$gst.ORIG" ]]; then sudo mv "$gst" "$gst.ORIG"; fi | |
sudo cp "gnome-shell-theme.gresource" "$gst" | |
popd 1>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment