Add random branch name generation with word lists

This commit is contained in:
Chris Wanstrath 2026-02-26 19:43:48 -08:00
parent f200942a52
commit 32da4e220f

View File

@ -10,6 +10,25 @@ import { requireApiKey } from "../env.ts"
import { renderMarkdown } from "../markdown.ts" import { renderMarkdown } from "../markdown.ts"
import { saveChanges } from "./helpers.ts" import { saveChanges } from "./helpers.ts"
const ADJECTIVES = [
"calm", "bold", "warm", "cool", "keen", "soft", "fast", "wild", "fair", "rare",
"deep", "dark", "pale", "wide", "slim", "tall", "glad", "pure", "safe", "free",
"hazy", "lazy", "cozy", "tiny", "vast", "busy", "easy", "gray", "gold", "blue",
"rosy", "wavy", "mild", "loud", "firm", "flat", "crisp", "dry", "raw", "odd",
]
const NOUNS = [
"fern", "dune", "cove", "pine", "reef", "hawk", "pond", "mesa", "vale", "glen",
"haze", "moss", "peak", "tide", "dawn", "lynx", "wren", "sage", "crag", "flint",
"leaf", "reed", "cave", "star", "gust", "surf", "opal", "lark", "vale", "plum",
"birch", "clay", "jade", "ivy", "fox", "elk", "bay", "ash", "dew", "oak",
]
function randomBranchName(): string {
const adj = ADJECTIVES[Math.floor(Math.random() * ADJECTIVES.length)]
const noun = NOUNS[Math.floor(Math.random() * NOUNS.length)]
return `${adj}-${noun}`
}
function fallbackBranchName(text: string): string { function fallbackBranchName(text: string): string {
return text return text
.toLowerCase() .toLowerCase()
@ -63,7 +82,7 @@ export async function action(
if (!branch && opts.print) { if (!branch && opts.print) {
branch = await branchFromPrompt(opts.print) branch = await branchFromPrompt(opts.print)
} else if (!branch) { } else if (!branch) {
die("Branch name or prompt is required.") branch = randomBranchName()
} else if (branch.includes(" ")) { } else if (branch.includes(" ")) {
// If the "branch" contains spaces, it's actually a prompt — derive the branch name // If the "branch" contains spaces, it's actually a prompt — derive the branch name
prompt = branch prompt = branch