Repository navigation
Expand file tree
/
Copy pathdevmode
More file actions
executable file
·265 lines (226 loc) · 7.46 KB
/
Copy pathdevmode
File metadata and controls
executable file
·265 lines (226 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
# Devmode TUI (Esa Lintang 2025)
# Version: Runtime Sync (copy only when running, auto cleanup on stop)
CONFIG_DIR="$HOME/devmode/config"
SPCK_DIR="/sdcard/android/data/io.spck/files"
SPCK_NODE_DIR="/sdcard/android/data/io.spck.editor.node/files"
ACODE_DIR="/sdcard/acode"
mkdir -p "$CONFIG_DIR"
# Colors
red='\e[31m'; green='\e[32m'; bgreen='\e[1;32m'; yellow='\e[33m'; blue='\e[34m'; white='\e[37m'; b='\e[1;37m'; reset='\e[0m'
exec 3>&2 2>/dev/null
box_header() {
local title="$1"
echo -e "${blue}┌───────────────────────────────────────────────┐${reset}"
printf "${blue}│${reset} ${yellow}%s${reset}\n" "$title"
echo -e "${blue}└───────────────────────────────────────────────┘${reset}\n"
}
select_multiple() {
local title="$1"; shift
local -n items=$1
local -n selected=$2
local index=0
local total=${#items[@]}
draw() {
clear
box_header "$title"
echo -e "${white}Use ↑ ↓ to navigate, Space to select, Enter to continue.${reset}\n"
for i in "${!items[@]}"; do
if [[ ${selected[$i]} == true ]]; then
mark="${bgreen}✓${reset}"
else
mark="${b}•${reset}"
fi
if [[ $i -eq $index ]]; then
echo -e " ${b} → ${mark} ${yellow}${items[$i]}${reset}"
else
echo -e " ${mark} ${white}${items[$i]}${reset}"
fi
done
}
draw
while true; do
IFS= read -rsn1 key 2>/dev/null || true
if [[ $key == $'\x1b' ]]; then
read -rsn2 key
case "$key" in
"[A") ((index--)); ((index < 0)) && index=$((total - 1)); draw ;;
"[B") ((index++)); ((index >= total)) && index=0; draw ;;
esac
elif [[ $key == " " ]]; then
selected[$index]=$([[ ${selected[$index]} == true ]] && echo false || echo true)
draw
elif [[ $key == "" ]]; then
break
fi
done
}
select_one() {
local title="$1"; shift
local -n items=$1
local -n chosen=$2
local index=0
local total=${#items[@]}
draw() {
clear
box_header "$title"
echo -e "${white}Use ↑ ↓ to navigate, Enter to select.${reset}\n"
for i in "${!items[@]}"; do
if [[ $i -eq $index ]]; then
echo -e " ${b} → ${yellow}${items[$i]}${reset}"
else
echo -e " ${white}${items[$i]}${reset}"
fi
done
}
draw
while true; do
IFS= read -rsn1 key 2>/dev/null || true
if [[ $key == $'\x1b' ]]; then
read -rsn2 key
case "$key" in
"[A") ((index--)); ((index < 0)) && index=$((total - 1)); draw ;;
"[B") ((index++)); ((index >= total)) && index=0; draw ;;
esac
elif [[ $key == "" ]]; then
chosen="${items[$index]}"
break
fi
done
}
FILTER_LIST=(
"node_modules"
".git"
"dist"
"build"
"out"
"vendor"
".vscode"
"__pycache__"
"*.lock"
"*.log"
"*.egg-info"
"*.dist-info"
)
create_filter_file() {
local f="$HOME/.devmode_filter"
echo "# rsync filter" > "$f"
for pattern in "${FILTER_LIST[@]}"; do
echo "- $pattern" >> "$f"
echo "- $pattern/**" >> "$f"
done
echo "+ *" >> "$f"
echo "$f"
}
set_workspace() {
clear
box_header "🛠️ Create New Workspace"
echo -e "${blue}🔍 Scanning current directory...${reset}"
files=($(ls))
declare -a selected_flags
select_multiple "📦 Select files/folders to include" files selected_flags
chosen_items=()
for i in "${!files[@]}"; do
if [[ ${selected_flags[$i]} == true ]]; then
chosen_items+=("${files[$i]}")
fi
done
if [ ${#chosen_items[@]} -eq 0 ]; then
echo -e "${red}⚠️ No files selected.${reset}"
return
fi
read -p "📝 Enter workspace name: " name
editors=("SPCK" "SPCK Node" "Acode")
select_one "🎨 Choose editor for this workspace" editors chosen_editor
case "$chosen_editor" in
"SPCK") editor_dir="$SPCK_DIR" ;;
"SPCK Node") editor_dir="$SPCK_NODE_DIR" ;;
"Acode") editor_dir="$ACODE_DIR" ;;
esac
cat > "$CONFIG_DIR/$name.json" <<EOF
{
"path": "$(pwd)",
"editor": "$chosen_editor",
"editor_dir": "$editor_dir",
"name": "$name",
"files": [$(printf '"%s",' "${chosen_items[@]}" | sed 's/,$//')]
}
EOF
echo -e "${green}✅ Workspace '$name' saved. Run it with:${reset}"
echo -e " ${blue}devmode run${reset}"
}
run_workspace() {
clear
box_header "🚀 Run Workspace"
files=("$CONFIG_DIR"/*.json)
[ ${#files[@]} -eq 0 ] && echo -e "${red}⚠️ No workspace found.${reset}" && return
options=()
for f in "${files[@]}"; do
options+=("$(basename "$f" .json)")
done
select_one "📂 Choose a workspace to run" options chosen
CONFIG_PATH="$CONFIG_DIR/$chosen.json"
workspace=$(jq -r '.path' "$CONFIG_PATH")
editor_dir=$(jq -r '.editor_dir' "$CONFIG_PATH")
name=$(jq -r '.name' "$CONFIG_PATH")
target_dir="$editor_dir/$name"
echo -e "${green}📂 Active Sync: ${yellow}$chosen${reset}"
echo "Project : $workspace"
echo "Editor : $target_dir"
sleep 1
filter_file=$(create_filter_file)
mkdir -p "$target_dir"
echo -e "\n${blue}📁 Copying initial files to editor...${reset}"
files_list=$(jq -r '.files[]' "$CONFIG_PATH")
for item in $files_list; do
if [ -e "$workspace/$item" ]; then
rsync -rt --checksum --filter="merge $filter_file" "$workspace/$item" "$target_dir/"
fi
done
echo -e "${green}✅ Copy complete. Syncing every 1 second...${reset}"
cleanup() {
echo -e "\n🧹 Stopping sync and cleaning up editor folder..."
rm -rf "$target_dir"
rm -f "$filter_file"
echo -e "${yellow}✅ Workspace '$chosen' closed.${reset}"
exit 0
}
trap cleanup INT
while true; do
rsync -rt --checksum --filter="merge $filter_file" "$target_dir/" "$workspace/" 2>/dev/null
sleep 1
done
}
remove_workspace() {
clear
box_header "🗑️ Remove Workspace"
files=("$CONFIG_DIR"/*.json)
[ ${#files[@]} -eq 0 ] && echo -e "${red}⚠️ No workspace to remove.${reset}" && return
options=()
for f in "${files[@]}"; do
options+=("$(basename "$f" .json)")
done
declare -a sel
select_multiple "Select workspace(s) to delete" options sel
for i in "${!options[@]}"; do
if [[ ${sel[$i]} == true ]]; then
rm -f "$CONFIG_DIR/${options[$i]}.json"
echo -e "${red}🗑️ Workspace '${options[$i]}' removed.${reset}"
fi
done
}
show_help() {
box_header "📘 Devmode CLI Help"
echo -e "${blue}Usage:${reset}"
echo " devmode set → Save a new workspace configuration"
echo " devmode run → Copy and start real-time sync"
echo " devmode rm → Delete saved workspace(s)"
echo " devmode help → Show this help menu"
}
case "$1" in
create-new-workspace|set) set_workspace ;;
start-workspace|run) run_workspace ;;
remove-workspace|rm) remove_workspace ;;
help|"") show_help ;;
*) echo -e "${red}Unknown command. Use 'devmode help'.${reset}" ;;
esac