Skip to content

Instantly share code, notes, and snippets.

View PhrozenByte's full-sized avatar

Daniel Rudolf PhrozenByte

View GitHub Profile
@PhrozenByte
PhrozenByte / multihead
Last active June 7, 2026 08:02
Toggles external monitors on/off.
#!/bin/bash
# multihead.sh - Toggles external monitors on/off.
#
# Copyright (C) 2021 Daniel Rudolf (<https://www.daniel-rudolf.de>)
# License: The MIT License <http://opensource.org/licenses/MIT>
#
# SPDX-License-Identifier: MIT
APP_NAME="$(basename "${BASH_SOURCE[0]}")"
@PhrozenByte
PhrozenByte / mimetypes.sh
Last active May 13, 2026 23:50
Load default applications for MIME types from a JSON file.
#!/bin/bash
# mimetypes.sh
# Load default applications for MIME types from a JSON file.
#
# This script reads MIME type <> default application mappings from JSON files
# (pass filesystem paths as script arguments) and configures defaults via
# `xdg-mime default <application> <MIME type>`.
#
# Missing or uninstalled applications are ignored. If the first listed
# application is not installed, the next one is used as fallback.
@PhrozenByte
PhrozenByte / gnome-extensions.sh
Last active May 13, 2026 23:51
Installs GNOME Shell extensions directly from extensions.gnome.org.
#!/bin/bash
# gnome-extensions.sh
# Installs GNOME Shell extensions directly from extensions.gnome.org.
#
# This script takes GNOME Shell extension UUIDs as arguments and fetches,
# downloads, and installs the latest version on `extensions.gnome.org` that is
# compatible with the locally installed GNOME Shell version.
#
# Note that GNOME Shell will not automatically discover and activate newly
# installed extensions within the current session. In practice, this requires
@PhrozenByte
PhrozenByte / gsettings.sh
Last active May 13, 2026 23:58
Loads GSettings and dconf configuration values from a JSON file.
#!/bin/bash
# gsettings.sh
# Loads GSettings and dconf configuration values from a JSON file.
#
# This script reads GSettings and dconf configuration values from a JSON file
# (pass a filesystem path as the only argument) and applies them to the local
# system. It optionally supports Flatpak applications, does not fail when a
# GSettings schema does not exist, and supports relocatable schemas.
#
# The JSON file must contain an object with the keys `"gsettings"` and
@PhrozenByte
PhrozenByte / systemd-mutex.sh
Last active March 23, 2026 21:39
Acquires and holds a mutex lock until terminated, designed to implement "mutex daemons" for Systemd.
#!/bin/bash
# systemd-mutex.sh
# Acquires and holds a mutex lock until terminated
#
# This script acquires and holds an exclusive (pass one of `--exclusive`, `-e`,
# or `-x`; default) or shared (pass `--shared` or `-s`) `flock` lock on the
# given file (pass required `MUTEX_FILE`) until terminated. If the lock cannot
# be acquired immediately, it either waits indefinitely until it can, or until
# the given timeout is exceeded (pass optional float `TIMEOUT` in seconds).
# Optionally, pass `-v` or `--verbose` to explain what's being done.
@PhrozenByte
PhrozenByte / chromium.sh
Last active September 24, 2025 11:46
Runs the 'org.chromium.Chromium' Flatpak with file forwarding enabled, and support for named and temporary Chromium profiles.
#!/bin/bash
##
# Run org.chromium.Chromium with file forwarding and temp profiles
#
# This wrapper script runs the 'org.chromium.Chromium' Flatpak and
# transparently adds the following options to Chromium's CLI:
# - Flatpak's `-u`, `--user`, `--system`, `--installation=NAME`, `--arch`,
# `--branch`, `--file-forwarding`, and `--verbose` options are passed to
# Flatpak; refer to flatpak-run(1) for details about these options
# - `--user-data-dir=NAME` additionally accepts existing user data directories
@PhrozenByte
PhrozenByte / bindfs.sh
Last active June 18, 2025 22:25
Bind mounts a directory with mapped IDs.
#!/bin/bash
##
# Bind mounts a directory with mapped IDs
#
# This script allows users running Linux 5.12 and later to easily create bind
# mounts with mapped IDs. For example, `bindfs.sh --idmap foo:bar src dst` bind
# mounts './src/' to './dst/', but all files owned by 'foo' appear as if they
# were owned by 'bar' instead. Files and directories owned by different users
# are kept as-is. This is the key difference to `mount --bind --map-users`.
# Usually one must be 'root' to run this script.
@PhrozenByte
PhrozenByte / config-helper.sh
Created May 27, 2025 09:58
Safely source sh-based config files with `bwrap`.
##
# Safely source sh-based config files with `bwrap`
#
# This function allows script developers to safely include sh-based config
# files, especially if the config file isn't owned by the running user. Most
# notably this function allows one to source config files owned by unprivileged
# users as root, without practically giving said unprivileged user root access.
# The file is sourced within an unprivileged bwrap container with read-only
# access to /usr and nothing else. The sh-based config file can thus do
# anything a sourced Bash file normally could (e.g. do complex calculations
@PhrozenByte
PhrozenByte / nm-systemd-dispatcher.sh
Created May 7, 2025 14:19
NetworkManager dispatcher script to start/stop a Systemd unit when a connection's status changes.
#!/bin/bash
# nm-systemd-dispatcher.sh
# Starts/stops a Systemd unit when a connection's status changes to up/down.
#
# Install this script to `/etc/NetworkManager/dispatcher.d/60-systemd.sh` and
# add the following section to your NetworkManager connection config in
# `/etc/NetworkManager/system-connections/*.nmconnection`:
# [user]
# systemd.unit=myservice.service
#
@PhrozenByte
PhrozenByte / mkarchiso-gnome.sh
Last active September 23, 2025 18:06
Creates a live ISO of Arch Linux with GNOME.
#!/bin/bash
# mkarchiso-gnome
# Creates a live ISO of Arch Linux with GNOME
#
# This script was created to ease creating live ISOs of Arch Linux with GNOME
# installed. It's highly customized to my personal preferences, thus it's
# likely not very useful as-is for most people, but it could be a good
# starting point for others to create their own custom live ISO.
#
# More about `mkarchiso`: https://wiki.archlinux.org/title/Archiso