1#!/usr/bin/env bash
2
3set -e
4
5RED='\033[0;31m'
6GREEN='\033[0;32m'
7YELLOW='\033[1;33m'
8BLUE='\033[0;34m'
9NC='\033[0m'
10
11CHANNEL="$1"
12COMMAND="$2"
13
14if [[ "$CHANNEL" != "stable" && "$CHANNEL" != "preview" && "$CHANNEL" != "nightly" && "$CHANNEL" != "dev" ]]; then
15 echo -e "${RED}Error: Invalid channel '$CHANNEL'. Must be one of: stable, preview, nightly, dev${NC}"
16 exit 1
17fi
18
19if [[ "$OSTYPE" == "darwin"* ]]; then
20 DB_BASE_DIR="$HOME/Library/Application Support/Zed/db"
21 DB_DIR="$DB_BASE_DIR/0-$CHANNEL"
22 DB_BACKUP_DIR="$DB_BASE_DIR/0-$CHANNEL.onboarding_backup"
23 case "$CHANNEL" in
24 stable) APP_NAME="Zed" ;;
25 preview) APP_NAME="Zed Preview" ;;
26 nightly) APP_NAME="Zed Nightly" ;;
27 dev) APP_NAME="Zed Dev" ;;
28 esac
29elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
30 DB_BASE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/zed/db"
31 DB_DIR="$DB_BASE_DIR/0-$CHANNEL"
32 DB_BACKUP_DIR="$DB_BASE_DIR/0-$CHANNEL.onboarding_backup"
33 case "$CHANNEL" in
34 stable) APP_NAME="zed" ;;
35 preview) APP_NAME="zed-preview" ;;
36 nightly) APP_NAME="zed-nightly" ;;
37 dev) APP_NAME="zed-dev" ;;
38 esac
39elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
40 LOCALAPPDATA_PATH="${LOCALAPPDATA:-$USERPROFILE/AppData/Local}"
41 DB_BASE_DIR="$LOCALAPPDATA_PATH/Zed/db"
42 DB_DIR="$DB_BASE_DIR/0-$CHANNEL"
43 DB_BACKUP_DIR="$DB_BASE_DIR/0-$CHANNEL.onboarding_backup"
44
45 case "$CHANNEL" in
46 stable) APP_NAME="Zed" ;;
47 preview) APP_NAME="Zed Preview" ;;
48 nightly) APP_NAME="Zed Nightly" ;;
49 dev) APP_NAME="Zed Dev" ;;
50 esac
51else
52 echo -e "${RED}Error: Unsupported OS type: $OSTYPE${NC}"
53 exit 1
54fi
55
56reset_onboarding() {
57 echo -e "${BLUE}=== Resetting $APP_NAME to First-Time User State ===${NC}"
58 echo ""
59
60 if [ ! -d "$DB_DIR" ]; then
61 echo -e "${YELLOW}No database directory found at: $DB_DIR${NC}"
62 echo "Zed will create a fresh database on next launch and show onboarding."
63 exit 0
64 fi
65
66 if [ -d "$DB_BACKUP_DIR" ]; then
67 echo -e "${RED}ERROR: Backup already exists at: $DB_BACKUP_DIR${NC}"
68 echo ""
69 echo "This suggests you've already run 'onboarding reset'."
70 echo "To avoid losing your original database, this script won't overwrite the backup."
71 echo ""
72 echo "Options:"
73 echo " 1. Run './script/onboarding $CHANNEL restore' to restore your original database"
74 echo " 2. Manually remove the backup if you're sure: rm -rf $DB_BACKUP_DIR"
75 exit 1
76 fi
77
78 echo -e "${YELLOW}Moving $DB_DIR to $DB_BACKUP_DIR${NC}"
79 mv "$DB_DIR" "$DB_BACKUP_DIR"
80
81 echo -e "${GREEN}✓ Backed up: $DB_BACKUP_DIR${NC}"
82 echo ""
83 echo -e "${GREEN}Success! Zed has been reset to first-time user state.${NC}"
84 echo ""
85 echo "Next steps:"
86 echo " 1. Start Zed - you should see the onboarding flow"
87 echo " 2. When done testing, run: ./script/onboarding $CHANNEL restore"
88 echo ""
89 echo -e "${YELLOW}Note: All your workspace data is safely preserved in the backup.${NC}"
90}
91
92restore_onboarding() {
93 echo -e "${BLUE}=== Restoring Original $APP_NAME Database ===${NC}"
94 echo ""
95
96 if [ ! -d "$DB_BACKUP_DIR" ]; then
97 echo -e "${RED}ERROR: No backup found at: $DB_BACKUP_DIR${NC}"
98 echo ""
99 echo "Run './script/onboarding $CHANNEL reset' first to create a backup."
100 exit 1
101 fi
102
103 if [ -d "$DB_DIR" ]; then
104 echo -e "${YELLOW}Removing current database directory: $DB_DIR${NC}"
105 rm -rf "$DB_DIR"
106 fi
107
108 echo -e "${YELLOW}Restoring $DB_BACKUP_DIR to $DB_DIR${NC}"
109 mv "$DB_BACKUP_DIR" "$DB_DIR"
110
111 echo -e "${GREEN}✓ Restored: $DB_DIR${NC}"
112 echo ""
113 echo -e "${GREEN}Success! Your original database has been restored.${NC}"
114}
115
116show_status() {
117 echo -e "${BLUE}=== Zed Onboarding Test Status ===${NC}"
118 echo ""
119
120 if [ -d "$DB_BACKUP_DIR" ]; then
121 echo -e "${YELLOW}Status: TESTING MODE${NC}"
122 echo " • Original database: $DB_BACKUP_DIR"
123 echo " • Zed is using: $DB_DIR"
124 echo " • Run './script/onboarding $CHANNEL restore' to return to normal"
125 elif [ -d "$DB_DIR" ]; then
126 echo -e "${GREEN}Status: NORMAL${NC}"
127 echo " • Zed is using: $DB_DIR"
128 echo " • Run './script/onboarding $CHANNEL reset' to test onboarding"
129 else
130 echo -e "${BLUE}Status: NO DATABASE${NC}"
131 echo " • No Zed database directory exists yet"
132 echo " • Zed will show onboarding on next launch"
133 fi
134}
135
136case "${COMMAND:-}" in
137 reset)
138 reset_onboarding
139 ;;
140 restore)
141 restore_onboarding
142 ;;
143 status)
144 show_status
145 ;;
146 *)
147 echo -e "${BLUE}Zed Onboarding Test Script${NC}"
148 echo ""
149 echo "Usage: $(basename $0) [channel] <command>"
150 echo ""
151 echo "Commands:"
152 echo " reset - Back up current database and reset to show onboarding"
153 echo " restore - Restore the original database after testing"
154 echo " status - Show current testing status"
155 echo ""
156 echo "Channels:"
157 echo " stable, preview, nightly, dev"
158 echo ""
159 echo "Working with channel: $CHANNEL"
160 echo "Database directory: $DB_DIR"
161 echo ""
162 echo "Examples:"
163 echo " ./script/onboarding nightly reset # Reset nightly"
164 echo " ./script/onboarding stable reset # Reset stable"
165 echo " ./script/onboarding preview restore # Restore preview"
166 echo ""
167 echo "Workflow:"
168 echo " 1. Close Zed"
169 echo " 2. ./script/onboarding nightly reset"
170 echo " 3. Open Zed"
171 echo " 4. Test onboarding"
172 echo " 5. Close Zed"
173 echo " 6. ./script/onboarding nightly restore"
174 exit 1
175 ;;
176esac