-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
249 lines (215 loc) · 8.6 KB
/
index.html
File metadata and controls
249 lines (215 loc) · 8.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bash Script Tools</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/mode-sh.min.js"></script>
<style>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap");
body {
font-family: "Inter", sans-serif;
}
#editor {
height: 400px;
border: 1px solid #27272a;
border-radius: 0.5rem;
}
.ace_tooltip .ace_icon {
display: none !important;
}
.ace_tooltip {
white-space: pre-line !important;
}
</style>
</head>
<body class="bg-background min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<div class="mb-4">
<h1 class="text-3xl font-semibold mb-2">Bash Script Tools</h1>
<p class="text-muted-foreground">Format and lint your Bash scripts</p>
</div>
<div class="space-y-4">
<!-- Code Editor -->
<div>
<label class="block text-sm font-medium mb-2">Script</label>
<div id="editor"></div>
</div>
<!-- Action Buttons -->
<div class="flex gap-3">
<button
id="format-btn"
onclick="formatCode()"
class="inline-flex items-center px-4 py-2 bg-zinc-900 text-zinc-100 rounded-md hover:bg-zinc-800 focus:outline-none focus:ring-2 focus:ring-zinc-700 transition-colors font-medium text-sm border border-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span>Format</span>
</button>
<button
id="lint-btn"
onclick="checkCode()"
class="inline-flex items-center px-4 py-2 bg-zinc-900 text-zinc-100 rounded-md hover:bg-zinc-800 focus:outline-none focus:ring-2 focus:ring-zinc-700 transition-colors font-medium text-sm border border-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span>Lint</span>
</button>
<button
id="autofix-btn"
onclick="autofixCode()"
class="inline-flex items-center px-4 py-2 bg-zinc-900 text-zinc-100 rounded-md hover:bg-zinc-800 focus:outline-none focus:ring-2 focus:ring-zinc-700 transition-colors font-medium text-sm border border-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span>Autofix</span>
</button>
<button
id="autofix-ai-btn"
onclick="autofixAICode()"
class="inline-flex items-center px-4 py-2 bg-zinc-900 text-zinc-100 rounded-md hover:bg-zinc-800 focus:outline-none focus:ring-2 focus:ring-zinc-700 transition-colors font-medium text-sm border border-zinc-800 disabled:opacity-50 disabled:cursor-not-allowed"
>
<span>Autofix (AI)</span>
</button>
</div>
<!-- Output Box -->
<div>
<label class="block text-sm font-medium mb-2">Lint Output</label>
<div
id="output-box"
class="w-full min-h-[200px] px-4 py-3 bg-black text-zinc-300 border border-zinc-800 rounded-lg overflow-auto text-xs"
>
<div class="text-xs text-zinc-300 font-mono">
Paste your script in the editor above then press the Lint button
</div>
</div>
</div>
</div>
</div>
<script>
ace.config.set("basePath", "https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/");
const STORAGE_KEY = "bash-script-tools-content";
const editor = ace.edit("editor");
editor.session.setMode("ace/mode/sh");
editor.setOptions({
fontSize: "14px",
showPrintMargin: false,
showGutter: true,
highlightGutterLine: true,
});
// Load content from localStorage
const savedContent = localStorage.getItem(STORAGE_KEY);
if (savedContent) {
editor.setValue(savedContent, -1);
}
// Save content to localStorage on change
editor.session.on("change", function () {
localStorage.setItem(STORAGE_KEY, editor.getValue());
});
function setButtonsDisabled(disabled) {
document.getElementById("format-btn").disabled = disabled;
document.getElementById("lint-btn").disabled = disabled;
document.getElementById("autofix-btn").disabled = disabled;
document.getElementById("autofix-ai-btn").disabled = disabled;
}
async function formatCode() {
const code = editor.getValue();
setButtonsDisabled(true);
try {
const response = await fetch("/format", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "code=" + encodeURIComponent(code),
});
const formattedCode = await response.text();
const cursor = editor.getCursorPosition();
editor.setValue(formattedCode, -1);
editor.moveCursorToPosition(cursor);
} catch (error) {
console.error("Format error:", error);
} finally {
setButtonsDisabled(false);
}
}
function jumpToLine(lineNum, column) {
editor.gotoLine(lineNum, column || 0, true);
editor.focus();
}
async function checkCode() {
const code = editor.getValue();
editor.session.clearAnnotations();
setButtonsDisabled(true);
try {
const response = await fetch("/shellcheck", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "code=" + encodeURIComponent(code),
});
const result = await response.json();
document.getElementById("output-box").innerHTML = result.html;
// Add click handlers to line numbers
document.querySelectorAll(".line-link").forEach((link) => {
link.addEventListener("click", (e) => {
e.preventDefault();
const lineNum = parseInt(link.dataset.line);
// Find annotation for this line to get column
const annotation = result.annotations?.find((a) => a.row === lineNum - 1);
const column = annotation ? annotation.column : 0;
jumpToLine(lineNum, column);
});
});
if (result.annotations && result.annotations.length > 0) {
editor.session.setAnnotations(result.annotations);
}
} catch (error) {
console.error("Shellcheck error:", error);
document.getElementById("output-box").innerHTML =
'<div class="text-xs text-red-600 font-mono">Error running ShellCheck</div>';
} finally {
setButtonsDisabled(false);
}
}
async function autofixCode() {
const code = editor.getValue();
setButtonsDisabled(true);
try {
const response = await fetch("/autofix", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "code=" + encodeURIComponent(code),
});
const fixedCode = await response.text();
const cursor = editor.getCursorPosition();
editor.setValue(fixedCode, -1);
editor.moveCursorToPosition(cursor);
// Run shellcheck again to update annotations
await checkCode();
} catch (error) {
console.error("Autofix error:", error);
setButtonsDisabled(false);
}
}
async function autofixAICode() {
const code = editor.getValue();
setButtonsDisabled(true);
try {
const response = await fetch("/autofix-ai", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: "code=" + encodeURIComponent(code),
});
if (!response.ok) {
console.error("AI Autofix error:", response.status);
setButtonsDisabled(false);
return;
}
const fixedCode = await response.text();
const cursor = editor.getCursorPosition();
editor.setValue(fixedCode, -1);
editor.moveCursorToPosition(cursor);
// Run shellcheck again to update annotations
await checkCode();
} catch (error) {
console.error("AI Autofix error:", error);
setButtonsDisabled(false);
}
}
</script>
</body>
</html>