#!/usr/bin/env bash # Deploy a skill from this repo to dotfiles for system-wide availability set -euo pipefail SKILLS_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DOTFILES_REPO="$HOME/proj/dotfiles" SKILL_NAME="${1:-}" usage() { cat < Deploy a skill from ~/proj/skills to ~/proj/dotfiles for system-wide deployment. Arguments: skill-name Name of skill directory in skills/ Examples: $0 screenshot-latest $0 niri-window-capture This script: 1. Copies skill to dotfiles/claude/skills/ 2. Shows you the Nix config to add 3. Reminds you to rebuild You must manually: - Edit home/claude.nix - Edit home/opencode.nix - Run: sudo nixos-rebuild switch --flake .#delpad - Restart AI agents Available skills: EOF ls -1 "$SKILLS_REPO/skills" | grep -v template | sed 's/^/ /' exit 1 } if [[ -z "$SKILL_NAME" ]]; then usage fi SKILL_SOURCE="$SKILLS_REPO/skills/$SKILL_NAME" SKILL_DEST="$DOTFILES_REPO/claude/skills/$SKILL_NAME" # Validate skill exists if [[ ! -d "$SKILL_SOURCE" ]]; then echo "Error: Skill not found: $SKILL_SOURCE" >&2 echo "" >&2 usage fi # Validate dotfiles repo exists if [[ ! -d "$DOTFILES_REPO" ]]; then echo "Error: Dotfiles repo not found: $DOTFILES_REPO" >&2 exit 1 fi # Check if skill has SKILL.md if [[ ! -f "$SKILL_SOURCE/SKILL.md" ]]; then echo "Error: $SKILL_NAME missing SKILL.md" >&2 exit 1 fi # Check if already deployed if [[ -d "$SKILL_DEST" ]]; then echo "⚠️ Skill already deployed: $SKILL_DEST" read -p "Overwrite? [y/N] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Cancelled" exit 1 fi rm -rf "$SKILL_DEST" fi # Check for security docs SECURITY_WARNING="" if [[ -f "$SKILL_SOURCE/SECURITY.md" ]]; then SECURITY_WARNING=" ⚠️ ⚠️ ⚠️ SECURITY WARNING ⚠️ ⚠️ ⚠️ This skill has security documentation. READ BEFORE DEPLOYING: $SKILL_DEST/SECURITY.md Security-sensitive skills should only be deployed after: 1. Reviewing security documentation 2. Understanding risks and mitigations 3. Configuring protection mechanisms " fi echo "Deploying skill: $SKILL_NAME" echo "" echo "Source: $SKILL_SOURCE" echo "Dest: $SKILL_DEST" echo "" # Copy skill mkdir -p "$(dirname "$SKILL_DEST")" cp -r "$SKILL_SOURCE" "$SKILL_DEST" echo "✓ Skill copied to dotfiles" echo "" if [[ -n "$SECURITY_WARNING" ]]; then echo "$SECURITY_WARNING" fi # Function to inject config into Nix file inject_nix_config() { local target_file="$1" local config_block="$2" local marker="$3" # Unique string to check if already deployed if [[ ! -f "$target_file" ]]; then echo "⚠️ File not found: $target_file (skipping)" return fi if grep -q "$marker" "$target_file"; then echo "ℹ️ Config already present in $(basename "$target_file")" else echo "Injecting config into $(basename "$target_file")..." # Create backup cp "$target_file" "${target_file}.bak" # Insert before the last line (assuming it is '}') # We use a temporary file to construct the new content head -n -1 "$target_file" > "${target_file}.tmp" echo "$config_block" >> "${target_file}.tmp" tail -n 1 "$target_file" >> "${target_file}.tmp" mv "${target_file}.tmp" "$target_file" echo "✓ Updated $(basename "$target_file")" fi } echo "Configuring system..." echo "" # 1. Claude Code Config CLAUDE_CONFIG=" # Skill: $SKILL_NAME home.file.\".claude/skills/$SKILL_NAME\" = { source = ../claude/skills/$SKILL_NAME; recursive = true; };" inject_nix_config "$DOTFILES_REPO/home/claude.nix" "$CLAUDE_CONFIG" ".claude/skills/$SKILL_NAME" # 2. OpenCode Config OPENCODE_CONFIG=" # Skill: $SKILL_NAME home.file.\".config/opencode/skills/$SKILL_NAME\" = { source = ../claude/skills/$SKILL_NAME; recursive = true; };" inject_nix_config "$DOTFILES_REPO/home/opencode.nix" "$OPENCODE_CONFIG" ".config/opencode/skills/$SKILL_NAME" # 3. Antigravity / Global Config # Check if antigravity.nix exists, otherwise warn ANTIGRAVITY_NIX="$DOTFILES_REPO/home/antigravity.nix" if [[ -f "$ANTIGRAVITY_NIX" ]]; then # For global scripts, we need to find executable scripts in the skill SCRIPTS=$(find "$SKILL_SOURCE/scripts" -name "*.sh" -type f) if [[ -n "$SCRIPTS" ]]; then GLOBAL_CONFIG="" for script in $SCRIPTS; do SCRIPT_NAME=$(basename "$script") SCRIPT_NO_EXT="${SCRIPT_NAME%.*}" # If skill has only one script and it matches skill name or is 'search', use skill name # Otherwise use script name LINK_NAME="$SCRIPT_NO_EXT" GLOBAL_CONFIG="$GLOBAL_CONFIG # Skill: $SKILL_NAME ($SCRIPT_NAME) home.file.\".local/bin/$LINK_NAME\" = { source = ../claude/skills/$SKILL_NAME/scripts/$SCRIPT_NAME; executable = true; };" done inject_nix_config "$ANTIGRAVITY_NIX" "$GLOBAL_CONFIG" ".local/bin/$LINK_NAME" fi else echo "⚠️ $ANTIGRAVITY_NIX not found. Skipping global binary configuration." echo " To enable global binaries, create home/antigravity.nix and add it to your flake." fi echo "" echo "Deployment configured." echo "Run the following to apply changes:" echo "" echo " cd $DOTFILES_REPO" echo " sudo nixos-rebuild switch --flake .#delpad" echo "" echo "Then restart your agents."