diff --git a/README.md b/README.md index 6af503a..812086c 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,9 @@ On first run, LazyShell will guide you through: ```bash # Open configuration UI lazyshell config + +# Open GitHub page to create a new issue +lazyshell issue ``` ### Manual Environment Variables (Optional) diff --git a/src/index.ts b/src/index.ts index e3d97a9..a9a6ce4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { Command } from 'commander'; import { select, text as input, spinner, outro, isCancel, cancel, intro } from '@clack/prompts'; import chalk from 'chalk'; +import { execFile } from 'child_process'; import { info, print, runCommand, printWrapped } from './utils'; import { generateCommandStruct, getDefaultModel, getModelFromConfig, type ModelConfig } from './lib/ai'; import { getOrInitializeConfig } from './lib/config'; @@ -52,6 +53,27 @@ async function refineCommand(currentPrompt: string, command: string): Promise { + const issueUrl = 'https://github.com/bernoussama/lazyshell/issues/new'; + const [command, args] = + process.platform === 'darwin' + ? ['open', [issueUrl]] + : process.platform === 'win32' + ? ['cmd', ['/c', 'start', '', issueUrl]] + : ['xdg-open', [issueUrl]]; + + await new Promise((resolve, reject) => { + execFile(command, args, (error, _stdout, stderr) => { + if (error) { + const details = stderr?.trim() || error.message; + reject(new Error(`Failed to execute browser command: ${details}`)); + return; + } + resolve(); + }); + }); +} + const program = new Command(); program .version(require('../package.json').version) @@ -125,4 +147,18 @@ program await showConfigUI(); }); +program + .command('issue') + .description('Open browser to create a new GitHub issue') + .action(async () => { + try { + await openIssuePage(); + await print(chalk.green('Opened issue page in browser.')); + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + console.error(chalk.red(`Failed to open issue page: ${message}`)); + process.exit(1); + } + }); + program.parse(process.argv);