diff --git a/setup b/setup index bbfcf1a..f0909a2 100755 --- a/setup +++ b/setup @@ -72,6 +72,19 @@ setup_new() { echo -e "${BOLD}Setting up first device...${NC}" echo "" + # Ask for grapho repo URL and branch + echo -n "Your grapho flake repo URL (e.g., https://github.com/you/grapho): " + read -r grapho_url + [[ -z "$grapho_url" ]] && { err "Repo URL is required"; exit 1; } + + echo -n "Branch [master]: " + read -r grapho_branch + grapho_branch="${grapho_branch:-master}" + + # Build nix run command + local nix_run_cmd="nix run 'git+${grapho_url}?ref=${grapho_branch}'" + + echo "" mkdir -p "$USYNC_DIR" # Generate age key @@ -111,12 +124,23 @@ EOF git -C "$config_dir" commit -q --no-gpg-sign -m "Initial setup" fi + local age_key + age_key=$(grep 'AGE-SECRET-KEY' "$AGE_KEY_FILE") + + # Build instructions + local instructions + instructions="# On other devices, run: +${nix_run_cmd} -- '${age_key}' + +# To pair mobile: +${nix_run_cmd} -- mobile" + # Summary echo "" echo -e "${G}=== Setup Complete ===${NC}" echo "" echo "Your age key (SAVE THIS SOMEWHERE SAFE):" - echo -e "${BOLD}$(cat "$AGE_KEY_FILE" | grep 'AGE-SECRET-KEY')${NC}" + echo -e "${BOLD}${age_key}${NC}" echo "" if [[ -n "$device_id" ]]; then echo "Device ID: ${device_id:0:20}..." @@ -127,10 +151,25 @@ EOF echo " cd $config_dir && git remote add origin && git push -u origin main" echo "" echo " 2. On other devices, run:" - echo " nix run 'git+' -- " + echo " ${nix_run_cmd} -- " echo "" echo " 3. To pair mobile:" - echo " nix run 'git+' -- mobile" + echo " ${nix_run_cmd} -- mobile" + + # Copy to clipboard if possible + if has xclip; then + echo "$instructions" | xclip -selection clipboard + echo "" + ok "Instructions copied to clipboard!" + elif has wl-copy; then + echo "$instructions" | wl-copy + echo "" + ok "Instructions copied to clipboard!" + elif has pbcopy; then + echo "$instructions" | pbcopy + echo "" + ok "Instructions copied to clipboard!" + fi } # ============================================================================= @@ -144,6 +183,18 @@ setup_join() { echo -e "${BOLD}Joining existing setup...${NC}" echo "" + # Ask for grapho repo URL and branch + echo -n "Your grapho flake repo URL (e.g., https://github.com/you/grapho): " + read -r grapho_url + [[ -z "$grapho_url" ]] && { err "Repo URL is required"; exit 1; } + + echo -n "Branch [master]: " + read -r grapho_branch + grapho_branch="${grapho_branch:-master}" + + local nix_run_cmd="nix run 'git+${grapho_url}?ref=${grapho_branch}'" + + echo "" mkdir -p "$USYNC_DIR" # Handle @file syntax @@ -184,6 +235,14 @@ setup_join() { local devices_file="$USYNC_DIR/devices.json" echo "{\"devices\":{\"$(hostname)\":{\"id\":\"$device_id\",\"added\":\"$(date -Iseconds)\"}}}" > "$devices_file" + # Build instructions + local instructions + instructions="# Add this device on your other machines: +${nix_run_cmd} -- add $device_id $(hostname) + +# To pair mobile: +${nix_run_cmd} -- mobile" + echo "" echo -e "${G}=== Joined! ===${NC}" echo "" @@ -191,11 +250,26 @@ setup_join() { echo "This device: ${device_id:0:20}..." echo "" echo "Add this device on your other machines:" - echo -e " ${BOLD}nix run 'git+' -- add $device_id $(hostname)${NC}" + echo -e " ${BOLD}${nix_run_cmd} -- add $device_id $(hostname)${NC}" fi echo "" - echo "To pair mobile: nix run 'git+' -- mobile" + echo "To pair mobile: ${nix_run_cmd} -- mobile" echo "To sync: ./scripts/usync" + + # Copy to clipboard if possible + if has xclip; then + echo "$instructions" | xclip -selection clipboard + echo "" + ok "Instructions copied to clipboard!" + elif has wl-copy; then + echo "$instructions" | wl-copy + echo "" + ok "Instructions copied to clipboard!" + elif has pbcopy; then + echo "$instructions" | pbcopy + echo "" + ok "Instructions copied to clipboard!" + fi } # =============================================================================