#!/bin/bash # Omarchy 4 post-install configurator. # # Step 1 - Remove: pick preinstalled packages and web apps to remove, and # optionally disable their default shortcuts. # Step 2 - Add: pick desktop, system and developer tools to install. # # Ends with a summary table: item | status | action verified. # # Usage: config_installer.sh [--dry-run] # # --dry-run Show what would happen without changing anything. Without a # terminal, every item is selected and every prompt answered yes, # so the whole path runs unattended. # # Step 1 is adapted from https://github.com/maxart/omarchy-cleaner. For an # all-or-nothing cleanup, Omarchy ships `omarchy-remove-preinstalls`. OMARCHY_PATH="${OMARCHY_PATH:-/usr/share/omarchy}" APP_BINDINGS="$OMARCHY_PATH/default/hypr/bindings/applications.lua" USER_BINDINGS="$HOME/.config/hypr/bindings.lua" DESKTOP_DIR="$HOME/.local/share/applications" # Tools from mise install and upgrade as soon as they ship, as in Omarchy's # own mise stubs. export MISE_MINIMUM_RELEASE_AGE=0 # --------------------------------------------------------------------------- # Step 1 candidates: packages offered for removal (shown only when installed). # Base list: $OMARCHY_PATH/install/omarchy-base.packages # --------------------------------------------------------------------------- REMOVABLE_PACKAGES=( # Optional services - not preinstalled in Omarchy 4, but often added later "1password-beta" "1password-cli" "signal-desktop" "spotify" # Web apps fall back to chromium unless the default browser is Chromium-based "chromium" # Preinstalls also removed by `omarchy-remove-preinstalls` "aether" "cliamp" "moonlight-qt" "omacalc" "omacut" "omawrite" "pinta" # Uncomment to offer for removal # "kdenlive" # video editing # "libreoffice-fresh" # office suite # "localsend" # cross-platform file sharing # "obs-studio" # screencasting and streaming # "obsidian" # markdown notes # "xournalpp" # handwritten notes, useful in meetings # "lazydocker" # docker TUI # "docker" "docker-buildx" "docker-compose" # keep: classic docker setup ) # --------------------------------------------------------------------------- # Step 2 catalogue: "item|group|method|target|command" # method: pacman, aur, mise (global), uvtool (uv tool install), rustup # target: package / mise tool / PyPI name # command: binary used to detect existing copies (mise) and verify installs # --------------------------------------------------------------------------- CATALOGUE=( "librewolf|Desktop|aur|librewolf-bin|librewolf" "herdr|System|pacman|herdr|herdr" "caligula|System|pacman|caligula|caligula" "just|Dev CLI|mise|just|just" "uv|Dev CLI|mise|uv|uv" "ty|Dev CLI|mise|ty|ty" "jj|Dev CLI|mise|jj|jj" "pi|Dev CLI|mise|pi|pi" "hunk|Dev CLI|mise|aqua:modem-dev/hunk|hunk" "rustup|Rust + Python|rustup|rustup|rustup" "maturin|Rust + Python|uvtool|maturin|maturin" "cmake|Rust + Python|pacman|cmake|cmake" "pkgconf|Rust + Python|pacman|pkgconf|pkgconf" "cargo-binstall|Profiling|pacman|cargo-binstall|cargo-binstall" "py-spy|Profiling|uvtool|py-spy|py-spy" "perf|Profiling|pacman|perf|perf" ) RUST_COMPONENTS=(rust-analyzer clippy rustfmt) DRY_RUN=false INTERACTIVE=false [[ -t 0 && -t 1 ]] && INTERACTIVE=true SUMMARY=() # "itemstatusverified" # --------------------------------------------------------------------------- # UI helpers - fall back to defaults (select all, answer yes) when unattended # --------------------------------------------------------------------------- info() { printf '\033[1;34m==> %s\033[0m\n' "$*"; } warn() { printf '\033[1;33m⚠ %s\033[0m\n' "$*"; } note() { printf ' %s\n' "$*"; } confirm() { if $INTERACTIVE; then gum confirm "$1" else note "$1 → yes (unattended)" fi } # choose
; prints the selection. choose() { local header="$1" preselect="$2" shift 2 if $INTERACTIVE; then local selected=() [[ $preselect == all ]] && selected=(--selected "$(IFS=,; echo "$*")") gum choose --no-limit --height 20 --header "$header" "${selected[@]}" "$@" else printf '%s\n' "$@" fi } # Run a command, or only print it in dry-run mode. run() { if $DRY_RUN; then local line printf -v line '%q ' "$@" note "would run: ${line/#uv_cmd/uv}" else "$@" fi } # A dry run verifies nothing, so every row says "no" there. record() { local verified="$3" $DRY_RUN && verified=no SUMMARY+=("$1"$'\t'"$2"$'\t'"$verified") } # Record an attempted action: verified only when the check passes for real. record_action() { local item="$1" status="$2" check="$3" if $DRY_RUN; then record "$item" "$status" no elif eval "$check"; then record "$item" "$status" yes else record "$item" kept no fi } # --------------------------------------------------------------------------- # Step 1 - Remove # --------------------------------------------------------------------------- installed_packages() { local pkg for pkg in "${REMOVABLE_PACKAGES[@]}"; do pacman -Qq "$pkg" &>/dev/null && echo "$pkg" done } # Same detection as omarchy-webapp-remove: any launcher run through Omarchy's # web app launcher or one of its URL handlers. installed_webapps() { local file for file in "$DESKTOP_DIR"/*.desktop; do [[ -f $file ]] || continue grep -q '^Exec=.*\(omarchy-launch-webapp\|omarchy-webapp-handler\)' "$file" && basename "${file%.desktop}" done | sort -f } # Host of a URL without scheme, path and leading "www.". url_host() { local host="${1#*://}" host="${host%%/*}" echo "${host#www.}" } # Default application bindings (applications.lua) that launch the given item, # printed as "KEYLabel". Packages match on their base name in the action; # web apps match on the host of their URL, or the handler name for HEY/Zoom. find_bindings() { local kind="$1" name="$2" needle="" handler="" host="" exec_line line url [[ -f $APP_BINDINGS ]] || return if [[ $kind == package ]]; then needle="${name%-desktop}" needle="${needle%-beta}" needle="${needle%-cli}" [[ $name == lazydocker ]] && needle="docker-tui" [[ $name == chromium ]] && return # bound as the generic "browser" action else exec_line=$(grep -m1 '^Exec=' "$DESKTOP_DIR/$name.desktop" 2>/dev/null) if [[ $exec_line =~ omarchy-webapp-handler-([a-z0-9]+) ]]; then handler="${BASH_REMATCH[1]}" elif [[ $exec_line =~ (https?:/+[^\"\' ]+) ]]; then host=$(url_host "${BASH_REMATCH[1]}") fi [[ -n $handler || -n $host ]] || return fi while IFS= read -r line; do [[ $line =~ o\.bind\(\ *\"([^\"]+)\",\ *\"([^\"]+)\" ]] || continue local key="${BASH_REMATCH[1]}" label="${BASH_REMATCH[2]}" if [[ $kind == package ]]; then [[ $line =~ (omarchy|launch|tui)\ *=\ *\"[^\"]*$needle ]] || continue elif [[ $line =~ webapp\ *=\ *\"([^\"]+)\" ]]; then url=$(url_host "${BASH_REMATCH[1]}") if [[ -n $handler ]]; then [[ $url == *"$handler"* ]] || continue else [[ $url == "$host" ]] || continue fi else continue fi printf '%s\t%s\n' "$key" "$label" done <"$APP_BINDINGS" } # Disable bindings by appending hl.unbind() calls to the user bindings file. unbind_keys() { local keys=("$@") key added=0 ((${#keys[@]})) || return 0 if $DRY_RUN; then note "would add to $USER_BINDINGS:" printf ' hl.unbind("%s")\n' "${keys[@]}" return 0 fi mkdir -p "$(dirname "$USER_BINDINGS")" touch "$USER_BINDINGS" cp "$USER_BINDINGS" "$USER_BINDINGS.backup.$(date +%Y%m%d_%H%M%S)" for key in "${keys[@]}"; do grep -qF "hl.unbind(\"$key\")" "$USER_BINDINGS" && continue if ((added++ == 0)); then printf '\n-- Unbound by config_installer.sh for removed apps\n' >>"$USER_BINDINGS" fi printf 'hl.unbind("%s")\n' "$key" >>"$USER_BINDINGS" done note "Disabled $added shortcut(s) in $USER_BINDINGS" hyprctl reload &>/dev/null } step_remove() { info "Step 1 - Remove preinstalled apps and web apps" local packages webapps item readarray -t packages < <(installed_packages) readarray -t webapps < <(installed_webapps) if ((${#packages[@]} + ${#webapps[@]} == 0)); then note "Nothing to remove." return fi # Menu entries carry a type prefix so names with spaces stay unambiguous. local options=() for item in "${packages[@]}"; do options+=("📦 $item"); done for item in "${webapps[@]}"; do options+=("🌐 $item"); done local selection selection=$(choose "Select items to remove (space to toggle, enter to confirm)" none "${options[@]}") local sel_packages=() sel_webapps=() while IFS= read -r item; do case "$item" in "📦 "*) sel_packages+=("${item#📦 }") ;; "🌐 "*) sel_webapps+=("${item#🌐 }") ;; esac done <<<"$selection" # Everything not selected stays. for item in "${packages[@]}"; do [[ " ${sel_packages[*]} " == *" $item "* ]] || record "$item" kept yes done for item in "${webapps[@]}"; do printf '%s\n' "${sel_webapps[@]}" | grep -qxF "$item" || record "$item (web app)" kept yes done ((${#sel_packages[@]} + ${#sel_webapps[@]})) || { note "Nothing selected."; return; } echo "Selected for removal:" for item in "${sel_packages[@]}"; do note "📦 $item"; done for item in "${sel_webapps[@]}"; do note "🌐 $item"; done # Removing chromium breaks any web app left behind unless the default # browser is Chromium-based (see omarchy-launch-webapp). if printf '%s\n' "${sel_packages[@]}" | grep -qx chromium && ((${#webapps[@]} > ${#sel_webapps[@]})); then warn "Remaining web apps open in chromium unless the default browser is" warn "Chrome, Brave, Edge, Vivaldi, Opera or Helium. They will stop launching." fi # Default shortcuts launching the selection. local keys=() summary=() key label for item in "${sel_packages[@]}"; do while IFS=$'\t' read -r key label; do [[ -n $key ]] && keys+=("$key") && summary+=("⌨ $key → $label") done < <(find_bindings package "$item") done for item in "${sel_webapps[@]}"; do while IFS=$'\t' read -r key label; do [[ -n $key ]] && keys+=("$key") && summary+=("⌨ $key → $label") done < <(find_bindings webapp "$item") done readarray -t keys < <(printf '%s\n' "${keys[@]}" | sed '/^$/d' | sort -u) local unbind=false if ((${#keys[@]})); then echo "Default shortcuts launching these items:" printf ' %s\n' "${summary[@]}" | sort -u confirm "Disable these shortcuts in ~/.config/hypr/bindings.lua?" && unbind=true fi if ! confirm "Remove the selected items? This cannot be undone."; then for item in "${sel_packages[@]}"; do record "$item" kept yes; done for item in "${sel_webapps[@]}"; do record "$item (web app)" kept yes; done return fi $unbind && unbind_keys "${keys[@]}" for item in "${sel_packages[@]}"; do run sudo pacman -Rns --noconfirm "$item" record_action "$item" removed "! pacman -Qq '$item' &>/dev/null" done for item in "${sel_webapps[@]}"; do run env OMARCHY_REMOVE_NOTIFY=false omarchy-webapp-remove "$item" record_action "$item (web app)" removed "[[ ! -e '$DESKTOP_DIR/$item.desktop' ]]" done ((${#sel_webapps[@]})) && ! $DRY_RUN && update-desktop-database "$DESKTOP_DIR" &>/dev/null } # --------------------------------------------------------------------------- # Step 2 - Add # --------------------------------------------------------------------------- # First version number printed by " --version". binary_version() { "$1" --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -1 } # True when $2 is a strictly newer version than $1. version_newer() { [[ $1 != "$2" && $(printf '%s\n%s\n' "$1" "$2" | sort -V | tail -1) == "$2" ]] } # Copies of on PATH that mise does not manage: cargo installs, other # pacman packages (e.g. jujutsu-git), npm globals, standalone installers. # Omarchy's lazy mise stubs in ~/.local/bin and mise's own paths are skipped. foreign_copies() { local command="$1" path real while IFS= read -r path; do real=$(readlink -f "$path") [[ $real == */mise/shims/* ]] && continue [[ $real == */mise/installs/* && $real != */node_modules/* ]] && continue grep -qs '^mise use -g' "$path" && continue echo "$path" done < <(type -ap "$command" | awk '!seen[$0]++') } # Print the removal command for a foreign copy, or nothing when its source is # unknown (then it is left alone). removal_command() { local path="$1" real owner crate real=$(readlink -f "$path") if owner=$(pacman -Qoq "$path" 2>/dev/null); then echo "sudo pacman -Rns --noconfirm $owner" elif [[ $path == "$HOME/.cargo/bin/"* ]]; then crate=$(cargo install --list 2>/dev/null | awk -v bin="$(basename "$path")" '/^[^ ]/{c=$1} $1==bin && /^ /{print c}') if [[ -n $crate ]]; then echo "cargo uninstall $crate" else echo "rm -f $path" # standalone installer, e.g. uv's fi elif [[ $real =~ /lib/node_modules/((@[^/]+/)?[^/]+)/ ]]; then echo "$(dirname "$path")/npm uninstall -g ${BASH_REMATCH[1]}" fi } # Offer to remove copies of a mise-managed tool that are older than the # version mise would install. Each removal gets its own summary row. replace_foreign_copies() { local command="$1" target="$2" latest path version how latest=$(mise latest "$target" 2>/dev/null) [[ -n $latest ]] || return while IFS= read -r path; do [[ -n $path ]] || continue version=$(binary_version "$path") how=$(removal_command "$path") local row="$command (old: $path)" if [[ -z $how ]]; then note "$path ($version): unknown source, left alone" record "$row" kept yes elif [[ -n $version ]] && version_newer "$version" "$latest"; then if confirm "Remove older $command $version at $path ($how) in favour of $latest?"; then # shellcheck disable=SC2086 # $how is a command line built above run $how record_action "$row" removed "[[ ! -e '$path' ]]" else record "$row" kept yes fi else note "$path ($version) is not older than $latest, left alone" record "$row" kept yes fi done < <(foreign_copies "$command") } # uv from PATH, or through mise right after it was installed there. A dry run # never reaches for mise, since `mise x` installs missing tools. uv_cmd() { if command -v uv &>/dev/null; then uv "$@" elif ! $DRY_RUN; then mise x uv -- uv "$@" else return 1 fi } install_rustup() { local item="$1" if pacman -Qq rustup &>/dev/null; then note "rustup already installed" elif pacman -Qq rust &>/dev/null; then if ! confirm "Replace the 'rust' package with rustup? (rustup then downloads the stable toolchain)"; then record "$item" kept yes return fi # rustup provides rust/cargo, so skipping dependency checks is safe here. run sudo pacman -Rdd --noconfirm rust run sudo pacman -S --noconfirm rustup else run sudo pacman -S --noconfirm rustup fi run rustup default stable run rustup component add "${RUST_COMPONENTS[@]}" record_action "$item" installed \ "pacman -Qq rustup &>/dev/null && rustup component list --installed | grep -q '^clippy'" } install_item() { local item group method target command IFS='|' read -r item group method target command <<<"$1" case "$method" in pacman | aur) if pacman -Qq "$target" &>/dev/null; then record "$item" kept yes return fi if [[ $method == aur ]]; then run omarchy-pkg-aur-add "$target" else run omarchy-pkg-add "$target" fi record_action "$item" installed "pacman -Qq '$target' &>/dev/null" ;; mise) replace_foreign_copies "$command" "$target" if mise ls --global --installed "$target" 2>/dev/null | grep -q .; then run mise up --quiet "$target" record "$item" kept yes return fi run mise use -g --quiet "$target" record_action "$item" installed "mise which '$command' &>/dev/null" ;; uvtool) if uv_cmd tool list 2>/dev/null | grep -q "^$target "; then record "$item" kept yes return fi run uv_cmd tool install "$target" record_action "$item" installed "uv_cmd tool list 2>/dev/null | grep -q '^$target '" ;; rustup) install_rustup "$item" ;; esac } step_add() { info "Step 2 - Add desktop, system and developer tools" local options=() entry item group for entry in "${CATALOGUE[@]}"; do IFS='|' read -r item group _ <<<"$entry" options+=("$group: $item") done local selection selection=$(choose "Select items to install (space to toggle, enter to confirm)" all "${options[@]}") for entry in "${CATALOGUE[@]}"; do IFS='|' read -r item group _ <<<"$entry" if grep -qxF "$group: $item" <<<"$selection"; then info "$item" install_item "$entry" else record "$item" kept yes fi done } # --------------------------------------------------------------------------- # Main # --------------------------------------------------------------------------- print_summary() { echo info "Summary$($DRY_RUN && echo ' (dry run - nothing was changed)')" { printf 'item\tstatus\taction verified\n' printf '%s\n' "${SUMMARY[@]}" } | column -t -s $'\t' } main() { case "${1:-}" in --dry-run) DRY_RUN=true ;; "") ;; *) echo "Usage: $0 [--dry-run]" >&2; exit 2 ;; esac for tool in gum mise omarchy-pkg-add omarchy-webapp-remove; do command -v "$tool" &>/dev/null || { echo "Missing $tool - is this Omarchy 4?" >&2; exit 1; } done if ! $INTERACTIVE && ! $DRY_RUN; then echo "No terminal: run interactively, or use --dry-run." >&2 exit 1 fi $DRY_RUN && warn "Dry run: nothing will be changed." if ! $DRY_RUN && ! sudo -v; then echo "sudo is required." >&2 exit 1 fi confirm "Step 1: remove preinstalled apps and web apps?" && step_remove confirm "Step 2: install desktop, system and developer tools?" && step_add print_summary } trap 'echo; echo "Cancelled"; print_summary; exit 1' INT main "$@"