1.3 KB45 lines
Blame
1import { log } from "@clack/prompts";
2import { existsSync, readFileSync } from "node:fs";
3import { join, dirname } from "node:path";
4import { execSync } from "node:child_process";
5
6export async function status() {
7 let dir = process.cwd();
8 let slDir: string | null = null;
9 while (dir !== dirname(dir)) {
10 if (existsSync(join(dir, ".sl", "config"))) {
11 slDir = join(dir, ".sl");
12 break;
13 }
14 dir = dirname(dir);
15 }
16
17 if (!slDir) {
18 log.error("Not in a Grove repository.");
19 process.exit(1);
20 }
21
22 const config = readFileSync(join(slDir, "config"), "utf-8");
23 const repoMatch = config.match(/reponame\s*=\s*(.+)/);
24 const ownerMatch = config.match(/owner\s*=\s*(.+)/);
25 const branchMatch = config.match(/selectivepulldefault\s*=\s*(.+)/);
26
27 const repo = repoMatch?.[1]?.trim() ?? "unknown";
28 const owner = ownerMatch?.[1]?.trim() ?? "unknown";
29 const branch = branchMatch?.[1]?.trim() ?? "main";
30
31 let current = "";
32 try {
33 current = execSync("sl log -r . --template {bookmarks}", { cwd: dir, stdio: "pipe" }).toString().trim();
34 } catch {}
35
36 const lines = [
37 `Repo: ${owner}/${repo}`,
38 `Branch: ${branch}`,
39 ];
40 if (current) lines.push(`At: ${current}`);
41 lines.push(`URL: https://grove.host/${owner}/${repo}`);
42
43 log.info(lines.join("\n"));
44}
45