#!/usr/bin/env bash set -euo pipefail source "$PWD/bash/bash_funcs" usage() { echo "Usage: $0 [link|remove|update]" exit 1 } XDG_CONFIG_HOME="$HOME/.config" XDG_DATA_HOME="$HOME/.local/share" # What operation to perform: link, remove, or update. OP="${1:-}" if [[ "$OP" == "" ]]; then OP="link" fi if [[ "$OP" != "link" && "$OP" != "remove" && "$OP" != "update" ]]; then usage fi GREEN_CHECK="$(printf '\x1b[32m✓\x1b[m')" BLACK=0 GREEN=2 YELLOW=3 BLUE=4 WHITE=7 # Print a status message with colors. status() { local text="$1" local bg_color="$2" local fg_color="$3" # Convert color numbers to ANSI codes. local bg_code=$((bg_color < 8 ? bg_color + 40 : bg_color + 92)) local fg_code=$((fg_color < 8 ? fg_color + 30 : fg_color + 82)) local padding padding=6 printf "\x1b[1;${bg_code};${fg_code}m %-${padding}s \x1b[m" "$text" } # Rendered status messages. SKIP="$(status "SKIP" "$BLUE" "$WHITE")" LINKED="$(status "LINKED" "$GREEN" "$BLACK")" COPIED="$(status "COPIED" "$GREEN" "$BLACK")" BACKUP="$(status "BACKUP" "$YELLOW" "$BLACK")" UNLINKED="$(status "UNLINK" "$GREEN" "$BLACK")" # Create or remove a symlink. link() { local op="$1" local source="$PWD/$2" local target="$3" local display_source="./$2" local display_target="${target/#$HOME/\~}" if [[ $op == "remove" ]]; then # Remove symlink. if [ -L "$target" ]; then rm "$target" echo "$UNLINKED $display_target" else echo "$SKIP No symlink to unlink at $display_target" fi else # Create symlink. mkdir -p "$(dirname "$target")" if [ -L "$target" ] && [ "$(readlink "$target")" = "$source" ]; then # Link already exists. echo "$SKIP Link $display_source -> $display_target exists" elif [ -L "$target" ]; then # Wrong symlink exists, just replace it. ln -sf "$source" "$target" echo "$LINKED $display_source -> $display_target (replaced wrong symlink)" elif [ -e "$target" ]; then # There's a real file/directory there. Back it up, then link. mv "$target" "$target.backup.$(date +%s)" ln -sf "$source" "$target" echo "$BACKUP Linked $display_source to $display_target (backed up existing)" else # Nothing there, create link. ln -sf "$source" "$target" echo "$LINKED $display_source -> $display_target" fi fi } # Ensure a command exists. If it does not, install it using the given command. ensure() { local name="$1" local cmd="$2" local script="$3" # Require curl for installation checks. if ! command -v curl &>/dev/null; then printf "curl is not installed. Please install curl first.\n" return fi if command -v "$cmd" &>/dev/null; then printf "%s %s is installed.\n" "$GREEN_CHECK" "$name" else printf "Installing %s...\n" "$name" eval "$script" fi } # Install a Python package using pipx (system-wide isolated installation). pipx_install() { local pkg="$1" pipx install "$pkg" pipx upgrade "$pkg" } os="$(which_os)" # Generally install or update stuff. if [[ $OP == "update" ]]; then git submodule update --init --recursive if [[ $os == "darwin" ]]; then bash "./scripts/setup-bash" fi case $os in darwin) ensure "Homebrew" "brew" "sh -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"" brew bundle --verbose ensure "pipx" "pipx" "brew install pipx" ;; esac # Ensure Nix is installed if ! command -v nix &>/dev/null; then echo "Nix not found, running install-nix..." bash "./scripts/install-nix" fi # Install/upgrade nix-profile packages echo "Updating nix-profile packages..." nix profile upgrade --all || nix profile install ./nix-profile fi # Bash. link "$OP" "bash/profile" "$HOME/.profile" link "$OP" "bash/bash_profile" "$HOME/.bash_profile" link "$OP" "bash/bashrc" "$HOME/.bashrc" link "$OP" "bash/bash_funcs" "$XDG_DATA_HOME/meowgorithm/bash_funcs" link "$OP" "pantera/env.asc" "$XDG_DATA_HOME/meowgorithm/env.asc" # Git link "$OP" "git/config" "$XDG_CONFIG_HOME/git/config" link "$OP" "git/ignore" "$XDG_CONFIG_HOME/git/ignore" link "$OP" "readline/inputrc" "$HOME/.inputrc" link "$OP" "ssh/config" "$HOME/.ssh/config" link "$OP" "rio/config.toml" "$XDG_CONFIG_HOME/rio/config.toml" link "$OP" "crush" "$XDG_CONFIG_HOME/crush" link "$OP" "vim" "$XDG_CONFIG_HOME/vim" link "$OP" "helix" "$XDG_CONFIG_HOME/helix" link "$OP" "prettier/prettierrc.yaml" "$HOME/.prettierrc.yaml" link "$OP" "emacs/init.el" "$HOME/.emacs.d/init.el" link "$OP" "zellij/config.kdl" "$XDG_CONFIG_HOME/zellij/config.kdl" link "$OP" "tmux/tmux.conf" "$HOME/.tmux.conf" # Neovim link "$OP" "nvim/init.lua" "$XDG_CONFIG_HOME/nvim/init.lua" link "$OP" "nvim/vsnip" "$XDG_CONFIG_HOME/.vsnip" link "$OP" "nvim/colors" "$XDG_CONFIG_HOME/nvim/colors" link "$OP" "nvim/autoload" "$XDG_CONFIG_HOME/nvim/autoload" # Kitty. link "$OP" "kitty/kitty.conf" "$XDG_CONFIG_HOME/kitty/kitty.conf" if [[ $os = "darwin" ]]; then link "$OP" "kitty/darwin.conf" "$XDG_CONFIG_HOME/kitty/os.conf" else link "$OP" "kitty/linux.conf" "$XDG_CONFIG_HOME/kitty/os.conf" fi # Ghostty link "$OP" "ghostty/config" "$XDG_CONFIG_HOME/ghostty/config" if [[ $os = "darwin" ]]; then link "$OP" "ghostty/darwin" "$XDG_CONFIG_HOME/ghostty/os" else link "$OP" "ghostty/linux" "$XDG_CONFIG_HOME/ghostty/os" fi # Fourmolu. link "$OP" "fourmolu/fourmolu.yaml" "$XDG_CONFIG_HOME/fourmolu.yaml" # Hyprland. case "$os" in nixos | fedora) link "$OP" "hypr/hyprland.conf" "$XDG_CONFIG_HOME/hypr/hyprland.conf" link "$OP" "waybar/" "$XDG_CONFIG_HOME/waybar" ;; esac linkScript() { link "$OP" "scripts/$1" "$HOME/.bin/$1" } # Scripts if [[ $os == "darwin" ]]; then linkScript "fix-docker-desktop" fi linkScript "gpg-edit-key" linkScript "gpg-send" linkScript "install-crush" linkScript "install-crush-version" linkScript "install-stuff" linkScript "install-v" linkScript "install-z.lua" linkScript "install-ghcup" linkScript "install-nix" linkScript "make-vid" linkScript "setup-mouse" linkScript "setup-wacom" linkScript "zellijls" linkScript "tm" linkScript "tmls" linkScript "uninstall-crush" link "$OP" "pantera/sessions.asc" "$XDG_DATA_HOME/meowgorithm/sessions.asc" linkScript "sessions" # Fedora bundle script case "$os" in fedora | linux) link "$OP" "scripts/dnf-bundle" "$HOME/.bin/bundle" link "$OP" "DNFfile" "$XDG_DATA_HOME/meowgorithm/DNFfile" link "$OP" "DNFfile.lock" "$XDG_DATA_HOME/meowgorithm/DNFfile.lock" ;; esac if [[ $os == "nixos" ]]; then linkScript "watch-waybar" fi # Fonts if [[ $os == "darwin" ]]; then # macOS fontDir="$HOME/Library/Fonts/Meowgorithm" else # Linux fontDir="$HOME/.local/share/fonts/Meowgorithm" fi if [[ -n "${fontDir:-}" ]]; then rm -rf "${fontDir/*:?/}" mkdir -p "$fontDir" if [[ $OP != "remove" ]]; then find ./fonts/ -type f \( -name "*.otf" -o -name "*.ttf" \) -exec cp {} "$fontDir/" \; if [[ $os != "darwin" ]] && command -v fc-cache &>/dev/null; then fc-cache -f "$fontDir" fi printf "%s Fonts\n" "$COPIED" else printf "%s Fonts\n" "$UNLINKED" fi fi