Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 5cb3cc0

Browse files
committed
fix(plugins/plugin-bash-like): clean up nested PTY execution path
Fixes #3493
1 parent 5690194 commit 5cb3cc0

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

plugins/plugin-bash-like/git/src/status-stripe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ const icon =
2929
*/
3030
async function reportCurrentBranch(tab: Tab, controller: StatusStripeController, { text }: StatusTextWithIcon) {
3131
try {
32-
const [isDirty, { content: branch }] = await Promise.all([
32+
const [isDirty, branch] = await Promise.all([
3333
// exit 0/1 indicates clean/dirty
34-
tab.REPL.rexec('git diff-index --quiet HEAD --')
34+
tab.REPL.qexec('git diff-index --quiet HEAD --')
3535
.then(() => false)
3636
.catch(() => true),
3737

3838
// exits with branch name
39-
tab.REPL.rexec<string>('git rev-parse --abbrev-ref HEAD')
39+
tab.REPL.qexec<string>('git rev-parse --abbrev-ref HEAD')
4040
])
4141

4242
if (branch) {

plugins/plugin-bash-like/src/lib/cmds/bash-like.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ const specialHandler = (args: Arguments) => {
239239
if (args.execOptions.type === ExecType.TopLevel) {
240240
throw new Error('this command is intended for internal consumption only')
241241
}
242-
args.execOptions.quiet = false
243242
return dispatchToShell(args)
244243
}
245244

plugins/plugin-bash-like/src/lib/cmds/catchall.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
*/
1616

1717
import Debug from 'debug'
18-
import { Streamable, isHeadless, inBrowser, hasProxy, Arguments, Registrar } from '@kui-shell/core'
18+
import {
19+
CodedError,
20+
ExecType,
21+
Streamable,
22+
isHeadless,
23+
inBrowser,
24+
hasProxy,
25+
Arguments,
26+
Registrar
27+
} from '@kui-shell/core'
1928

2029
const debug = Debug('plugins/bash-like/cmds/catchall')
2130

@@ -33,22 +42,28 @@ export const dispatchToShell = async ({
3342
createOutputStream
3443
}: Arguments) => {
3544
/** trim the first part of "/bin/sh: someNonExistentCommand: command not found" */
36-
const cleanUpError = (err: Error) => {
45+
const cleanUpError = (err: CodedError) => {
3746
if (err.message && typeof err.message === 'string') {
3847
err.message = err.message.replace(/[a-zA-Z0-9/]+:\s*/, '').trim()
3948
}
4049
throw err
4150
}
4251

52+
const useRaw =
53+
(execOptions.raw || execOptions.type === ExecType.Nested) &&
54+
execOptions.quiet === undefined &&
55+
execOptions.echo === undefined &&
56+
execOptions.replSilence === undefined
57+
4358
const eOptions =
44-
execOptions.raw || execOptions.isProxied
59+
useRaw || execOptions.isProxied
4560
? execOptions
4661
: Object.assign({}, { stdout: await createOutputStream() }, execOptions)
4762

48-
if (isHeadless() || (!inBrowser() && execOptions.raw)) {
63+
if (isHeadless() || (!inBrowser() && useRaw)) {
4964
const { doExec } = await import('./bash-like')
5065
const response = await doExec(command.replace(/^! /, ''), eOptions).catch(cleanUpError)
51-
if (execOptions.raw && typeof response === 'string') {
66+
if (useRaw && typeof response === 'string') {
5267
try {
5368
return JSON.parse(response)
5469
} catch (err) {
@@ -62,18 +77,13 @@ export const dispatchToShell = async ({
6277

6378
const exec = () => doExec(tab, block as HTMLElement, actualCommand, argvNoOptions, parsedOptions, eOptions)
6479

65-
if (
66-
execOptions.raw &&
67-
execOptions.quiet === undefined &&
68-
execOptions.echo === undefined &&
69-
execOptions.replSilence === undefined
70-
) {
71-
execOptions.quiet = true
72-
execOptions.echo = false
73-
execOptions.replSilence = true
80+
if (useRaw) {
81+
eOptions.quiet = true
82+
eOptions.echo = false
83+
eOptions.replSilence = true
7484

7585
let response = ''
76-
execOptions.onInit = () => (_: Streamable) => {
86+
eOptions.onInit = () => (_: Streamable) => {
7787
if (typeof _ === 'string') {
7888
response += _
7989
}

plugins/plugin-bash-like/src/pty/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ async function initOnMessage(
827827
// vi, then :wq, then :q, you will get an exit code of
828828
// 1, but with no output (!bytesWereWritten); note how
829829
// we treat this as "ok", i.e. no error thrown
830-
if (msg.exitCode !== 0 && bytesWereWritten) {
830+
if (msg.exitCode !== 0 && (bytesWereWritten || execOptions.onInit)) {
831831
const error = new Error('')
832832
if (sawCode === 409) error['code'] = 409
833833
// re: i18n, this is for tests

0 commit comments

Comments
 (0)