Skip to content

Instantly share code, notes, and snippets.

@euxn23
Created April 30, 2026 07:10
Show Gist options
  • Select an option

  • Save euxn23/aecef5f291d2dab06e4735b9f9a112ce to your computer and use it in GitHub Desktop.

Select an option

Save euxn23/aecef5f291d2dab06e4735b9f9a112ce to your computer and use it in GitHub Desktop.
worktrunk wrapper
#!/usr/bin/env bun
import { cli, define, plugin } from 'gunshi'
const witShell = `\
wit() {
local out
out="$(command wit "$@")"
exit_code=$?
if [[ exit_code -ne 0 ]]; then
echo "$out"
return exit_code
else
eval "$out"
fi
}
`
const options = plugin({
id: 'options',
setup: (ctx) => {
ctx.addGlobalOption('x', {
type: 'boolean',
short: 'x',
description: 'run claude code',
})
},
})
const switch_ = define({
name: 'switch',
args: {
interactive: {
type: 'boolean',
short: 'i',
default: false
}
},
run: async (ctx) => {
if (ctx.values.interactive) {
console.log(`wt switch $(git branch-i)`)
return
}
console.log(`wt switch`)
},
})
const fork = define({
name: 'fork',
args: {
name: {
type: 'positional',
required: true,
},
base: {
type: 'string',
required: false,
default: undefined
}
},
run: async (ctx) => {
if (ctx.values.base) {
console.log(`wt switch -c --base ${ctx.values.base} ${ctx.values.name}`)
return
}
console.log(`wt switch -c ${ctx.values.name}`)
}
})
const remove = define({
name: 'remove',
run: async (ctx) => {
console.log(`wt remove $(wt list | sed 's/\x1b\\[[0-9;]*m//g' | tail -n +2 | head -n -2 | awk '{print $2}' | sk)`)
}
})
const init = define({
name: 'init',
run: () => {
console.log(witShell)
},
})
const main = define({
name: 'wit',
})
await cli(Bun.argv.slice(2), main, {
name: 'wit',
version: '0.1.0',
renderHeader: async (ctx) => {
if (ctx.values.help) {
process.exitCode = 1
return 'A worktrunk wrapper.\nAdd `eval "$(command wit init)"` to .zshrc to activate automatic cd'
}
return ''
},
plugins: [options],
subCommands: {
init,
switch: switch_,
s: switch_,
fork,
f: fork,
remove,
rm: remove
},
}).catch(() => {
process.exit(1)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment