From ba69caaa6d6ea02c7f5fbc850d391348cef90fc4 Mon Sep 17 00:00:00 2001 From: Noah Penza <69229034+npenza@users.noreply.github.com> Date: Tue, 15 Jul 2025 14:39:07 +1000 Subject: [PATCH] Omarchy Theme Installer (#150) * Add omarchy theme remove * Add theme installer * Add migration to make theme management scripts executable * Refactor theme installation script to simplify directory structure and remove unnecessary symlinks. The script now directly clones themes into the ~/.config/omarchy/themes directory and updates paths accordingly for backgrounds and fonts. * Update permissions for theme scripts and remove unnecessary migration file * Refactor theme installation script to always use swaybg-next * Remove fonts from omarchy-theme-install * Refactor omarchy-theme-remove by swiitching to theme dir and removing unnecessary symlink checks * Refactor theme installer to use omarchy-theme-set * Fix Omarchy theme remove removing current theme and throwing error * Making theme management scripts quiet --- bin/omarchy-theme-install | 46 +++++++++++++++++++++++++++++++++ bin/omarchy-theme-remove | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 bin/omarchy-theme-install create mode 100755 bin/omarchy-theme-remove diff --git a/bin/omarchy-theme-install b/bin/omarchy-theme-install new file mode 100755 index 0000000..cd84ffc --- /dev/null +++ b/bin/omarchy-theme-install @@ -0,0 +1,46 @@ +#!/bin/bash + +# omarchy-theme-install: Install a new theme from a git repo for Omarchy +# Usage: omarchy-theme-install + +REPO_URL="$1" +THEMES_DIR="$HOME/.config/omarchy/themes" +THEME_NAME=$(basename "$REPO_URL" .git) +THEME_PATH="$THEMES_DIR/$THEME_NAME" +BACKGROUND_DIR="$HOME/.config/omarchy/backgrounds" +CURRENT_DIR="$HOME/.config/omarchy/current" + +set -e + +if [ -z "$1" ]; then + echo "Usage: omarchy-theme-install " + exit 1 +fi + +# Ensure theme directories exist +mkdir -p "$THEMES_DIR" "$BACKGROUND_DIR" "$CURRENT_DIR" + +# Remove existing theme if present +if [ -d "$THEME_PATH" ]; then + rm -rf "$THEME_PATH" +fi + +# Clone the repo directly to ~/.config/omarchy/themes +if ! git clone "$REPO_URL" "$THEME_PATH"; then + echo "Error: Failed to clone theme repo." + exit 1 +fi + +# Copy backgrounds if present +if [ -d "$THEME_PATH/backgrounds" ]; then + DEST_BG="$BACKGROUND_DIR/$THEME_NAME" + rm -rf "$DEST_BG" + mkdir -p "$DEST_BG" + cp -r "$THEME_PATH/backgrounds/." "$DEST_BG/" +fi + +# Apply the new theme with omarchy-theme-set +"$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$THEME_NAME" + +# Notify of the new theme +notify-send "Theme changed to $THEME_NAME" -t 2000 \ No newline at end of file diff --git a/bin/omarchy-theme-remove b/bin/omarchy-theme-remove new file mode 100755 index 0000000..e910746 --- /dev/null +++ b/bin/omarchy-theme-remove @@ -0,0 +1,53 @@ +#!/bin/bash + +# omarchy-theme-remove: Remove a theme from Omarchy by name +# Usage: omarchy-theme-remove + +THEME_NAME="$1" +THEMES_DIR="$HOME/.config/omarchy/themes" +BACKGROUND_DIR="$HOME/.config/omarchy/backgrounds" +CURRENT_DIR="$HOME/.config/omarchy/current" + +THEME_PATH="$THEMES_DIR/$THEME_NAME" +BACKGROUND_PATH="$BACKGROUND_DIR/$THEME_NAME" + +set -e + +if [ -z "$1" ]; then + echo "Usage: omarchy-theme-remove " + exit 1 +fi + +# Count available themes (directories in ~/.config/omarchy/themes) +THEMES=($(find "$THEMES_DIR" -mindepth 1 -maxdepth 1 -type d | sort)) +if [ ${#THEMES[@]} -le 1 ]; then + echo "Error: Cannot remove the last remaining theme. At least one theme must be installed." + exit 1 +fi + +# Check if theme exists before attempting removal +if [ ! -d "$THEME_PATH" ]; then + echo "Error: Theme '$THEME_NAME' not found." + exit 1 +fi + +# Check if the theme to be removed is the current theme +IS_CURRENT=0 +# Use readlink -f to resolve symlinks and get the absolute path +if [ "$(readlink -f "$CURRENT_DIR/theme")" = "$(readlink -f "$THEME_PATH")" ]; then + IS_CURRENT=1 +fi + +# If it is, switch to the next theme before removing +if [ $IS_CURRENT -eq 1 ]; then + "$HOME/.local/share/omarchy/bin/omarchy-theme-next" +fi + +# Now remove the theme directory and backgrounds for THEME_NAME +rm -rf "$THEME_PATH" + +if [ -d "$BACKGROUND_PATH" ]; then + rm -rf "$BACKGROUND_PATH" +fi + +notify-send "Theme '$THEME_NAME' removed." -t 2000 \ No newline at end of file