feat(tx): list sessions in table

This commit is contained in:
2023-12-18 19:00:22 +02:00
parent b52b5b99f4
commit 725dc192cb
2 changed files with 26 additions and 5 deletions

View File

@@ -61,7 +61,7 @@ export async function getCommandOutput(
const [cmd, ...args] = command.split(' ')
log(opts, '$ ' + command)
if (opts.dry) return { code: 0, output: '' }
const proc = spawn(cmd, args, { stdio: 'pipe' })
const proc = spawn(cmd, args, { stdio: 'pipe', shell: '/bin/zsh' })
return new Promise<{ code: number; output: string }>((resolve, reject) => {
let output = ''
proc.stdout.on('data', (data) => {

View File

@@ -81,7 +81,7 @@ const showCmd = new MassargCommand<Opts>({
})
.help({ bindOption: true, bindCommand: true })
const listCmd = new MassargCommand<Opts & { bare?: boolean }>({
const listCmd = new MassargCommand<Opts & { bare?: boolean; sessions?: boolean }>({
name: 'list',
aliases: ['ls'],
description: 'List all tmux configurations and sessions',
@@ -96,9 +96,20 @@ const listCmd = new MassargCommand<Opts & { bare?: boolean }>({
console.log(keys.join('\n'))
return
}
const sessions = await getCommandOutput(opts, 'tmux ls')
const sessionsOutput = await getCommandOutput(opts, 'tmux ls')
const sessions = sessionsOutput.output.replace(/\(created ([^)]+)\)/g, '$1')
const tbl = await getCommandOutput(
opts,
`echo ${JSON.stringify(
sessions,
)} | tblf -th "Name # Windows DDD MMM DD HH:MM:SS YYYY Status"`,
)
if (opts.sessions) {
console.log(tbl.output)
return
}
console.log('tmux sessions:\n')
console.log(indent(sessions.output))
console.log(indent(tbl.output))
console.log('tmux config files:\n')
console.log(
' - ' +
@@ -114,11 +125,21 @@ const listCmd = new MassargCommand<Opts & { bare?: boolean }>({
console.log(' - ' + keys.join('\n - '))
},
})
.flag({
name: 'verbose',
aliases: ['v'],
description: 'Verbose logs',
})
.flag({
name: 'bare',
aliases: ['b'],
description:
'Show only the tmux session names, without the config or formatting (useful for scripting)',
'Show only the tmux configuration names, without the sessions or formatting (useful for scripting)',
})
.flag({
name: 'sessions',
aliases: ['s'],
description: 'Show only the tmux sessions',
})
.help({ bindOption: true, bindCommand: true })