Skip to content

Commit 47c1758

Browse files
authored
fix(tabby-ui): fix that only bash code block can be execute in chat panel (#4076)
* feat(codeblock): support multiple shell languages for command execution * feat(codeblock): add placeholder comment for additional common shells
1 parent 3bd6076 commit 47c1758

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

ee/tabby-ui/components/ui/codeblock.tsx

+38-21
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ export const programmingLanguages: languageMap = {
7171
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
7272
}
7373

74+
const commonShells = [
75+
'sh',
76+
'bash',
77+
'zsh',
78+
'fish',
79+
'csh',
80+
'tcsh',
81+
'ksh',
82+
'dash',
83+
'cmd',
84+
'powershell',
85+
'pwsh',
86+
'shell'
87+
// add more common shells here
88+
]
89+
7490
export const generateRandomString = (length: number, lowercase = false) => {
7591
const chars = 'ABCDEFGHJKLMNPQRSTUVWXY3456789' // excluding similar looking characters like Z, 2, I, 1, O, 0
7692
let result = ''
@@ -102,7 +118,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
102118
}
103119

104120
const onRunCommand = () => {
105-
if (runShell && language === 'bash') {
121+
if (runShell && commonShells.includes(language.toLowerCase())) {
106122
runShell(value)
107123
}
108124
}
@@ -115,7 +131,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
115131
<div className="flex w-full items-center justify-between bg-zinc-800 px-6 py-2 pr-4 text-zinc-100">
116132
<span className="text-xs lowercase">{language}</span>
117133
<div className="flex items-center space-x-1">
118-
{runShell && language === 'bash' && (
134+
{runShell && commonShells.includes(language.toLowerCase()) && (
119135
<Tooltip>
120136
<TooltipTrigger asChild>
121137
<Button
@@ -152,7 +168,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
152168
)}
153169
{supportsOnApplyInEditorV2 &&
154170
onApplyInEditor &&
155-
!(runShell && language === 'bash') && (
171+
!(runShell && commonShells.includes(language.toLowerCase())) && (
156172
<Tooltip>
157173
<TooltipTrigger asChild>
158174
<Button
@@ -175,24 +191,25 @@ const CodeBlock: FC<CodeBlockProps> = memo(
175191
</TooltipContent>
176192
</Tooltip>
177193
)}
178-
{onApplyInEditor && !(runShell && language === 'bash') && (
179-
<Tooltip>
180-
<TooltipTrigger asChild>
181-
<Button
182-
variant="ghost"
183-
size="icon"
184-
className="text-xs hover:bg-[#3C382F] hover:text-[#F4F4F5] focus-visible:ring-1 focus-visible:ring-slate-700 focus-visible:ring-offset-0"
185-
onClick={() => onApplyInEditor(value, undefined)}
186-
>
187-
<IconApplyInEditor />
188-
<span className="sr-only">Apply in Editor</span>
189-
</Button>
190-
</TooltipTrigger>
191-
<TooltipContent>
192-
<p className="m-0">Apply in Editor</p>
193-
</TooltipContent>
194-
</Tooltip>
195-
)}
194+
{onApplyInEditor &&
195+
!(runShell && commonShells.includes(language.toLowerCase())) && (
196+
<Tooltip>
197+
<TooltipTrigger asChild>
198+
<Button
199+
variant="ghost"
200+
size="icon"
201+
className="text-xs hover:bg-[#3C382F] hover:text-[#F4F4F5] focus-visible:ring-1 focus-visible:ring-slate-700 focus-visible:ring-offset-0"
202+
onClick={() => onApplyInEditor(value, undefined)}
203+
>
204+
<IconApplyInEditor />
205+
<span className="sr-only">Apply in Editor</span>
206+
</Button>
207+
</TooltipTrigger>
208+
<TooltipContent>
209+
<p className="m-0">Apply in Editor</p>
210+
</TooltipContent>
211+
</Tooltip>
212+
)}
196213
<Tooltip>
197214
<TooltipTrigger asChild>
198215
<Button

0 commit comments

Comments
 (0)