When run via shebang, bun prepends itself so -c appears at argv[2] instead of argv[1]. Search both positions to support either mode.
22 lines
731 B
TypeScript
Executable File
22 lines
731 B
TypeScript
Executable File
#!/usr/bin/env bun
|
|
import { program } from './setup'
|
|
|
|
const isCliUser = process.env.USER === 'cli'
|
|
const noArgs = process.argv.length <= 2
|
|
const isTTY = !!process.stdin.isTTY
|
|
|
|
// SSH login shell passes commands as: toes -c "command args"
|
|
// With shebang, argv is [bun, script, -c, cmd]; compiled, it's [toes, -c, cmd]
|
|
const cIndex = process.argv[1] === '-c' ? 1 : process.argv[2] === '-c' ? 2 : -1
|
|
const shellExec = cIndex !== -1 ? process.argv.slice(cIndex + 1).join(' ') : null
|
|
|
|
if (shellExec) {
|
|
const tokens = shellExec.split(/\s+/).filter(Boolean)
|
|
program.parse(['node', 'toes', ...tokens])
|
|
} else if (isCliUser && noArgs && isTTY) {
|
|
const { shell } = await import('./shell')
|
|
await shell()
|
|
} else {
|
|
program.parse()
|
|
}
|