Ask for grapho repo URL and copy instructions to clipboard

- Prompt for grapho flake URL and branch (defaults to master)
- Substitute into nix run commands in output
- Auto-copy instructions to clipboard (xclip/wl-copy/pbcopy)
- Apply same changes to both setup_new and setup_join

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 02:59:45 -05:00
parent 45fc5ba08c
commit 2cb8c02494

84
setup
View File

@@ -72,6 +72,19 @@ setup_new() {
echo -e "${BOLD}Setting up first device...${NC}" echo -e "${BOLD}Setting up first device...${NC}"
echo "" 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" mkdir -p "$USYNC_DIR"
# Generate age key # Generate age key
@@ -111,12 +124,23 @@ EOF
git -C "$config_dir" commit -q --no-gpg-sign -m "Initial setup" git -C "$config_dir" commit -q --no-gpg-sign -m "Initial setup"
fi 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} -- <config-git-url> '${age_key}'
# To pair mobile:
${nix_run_cmd} -- mobile"
# Summary # Summary
echo "" echo ""
echo -e "${G}=== Setup Complete ===${NC}" echo -e "${G}=== Setup Complete ===${NC}"
echo "" echo ""
echo "Your age key (SAVE THIS SOMEWHERE SAFE):" 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 "" echo ""
if [[ -n "$device_id" ]]; then if [[ -n "$device_id" ]]; then
echo "Device ID: ${device_id:0:20}..." echo "Device ID: ${device_id:0:20}..."
@@ -127,10 +151,25 @@ EOF
echo " cd $config_dir && git remote add origin <your-git-url> && git push -u origin main" echo " cd $config_dir && git remote add origin <your-git-url> && git push -u origin main"
echo "" echo ""
echo " 2. On other devices, run:" echo " 2. On other devices, run:"
echo " nix run 'git+<your-grapho-repo>' -- <config-git-url> <age-key>" echo " ${nix_run_cmd} -- <config-git-url> <age-key>"
echo "" echo ""
echo " 3. To pair mobile:" echo " 3. To pair mobile:"
echo " nix run 'git+<your-grapho-repo>' -- 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 -e "${BOLD}Joining existing setup...${NC}"
echo "" 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" mkdir -p "$USYNC_DIR"
# Handle @file syntax # Handle @file syntax
@@ -184,6 +235,14 @@ setup_join() {
local devices_file="$USYNC_DIR/devices.json" local devices_file="$USYNC_DIR/devices.json"
echo "{\"devices\":{\"$(hostname)\":{\"id\":\"$device_id\",\"added\":\"$(date -Iseconds)\"}}}" > "$devices_file" 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 ""
echo -e "${G}=== Joined! ===${NC}" echo -e "${G}=== Joined! ===${NC}"
echo "" echo ""
@@ -191,11 +250,26 @@ setup_join() {
echo "This device: ${device_id:0:20}..." echo "This device: ${device_id:0:20}..."
echo "" echo ""
echo "Add this device on your other machines:" echo "Add this device on your other machines:"
echo -e " ${BOLD}nix run 'git+<your-grapho-repo>' -- add $device_id $(hostname)${NC}" echo -e " ${BOLD}${nix_run_cmd} -- add $device_id $(hostname)${NC}"
fi fi
echo "" echo ""
echo "To pair mobile: nix run 'git+<your-grapho-repo>' -- mobile" echo "To pair mobile: ${nix_run_cmd} -- mobile"
echo "To sync: ./scripts/usync" 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
} }
# ============================================================================= # =============================================================================