From dce63526e190ce5c54b5c63557b111a429b6842b Mon Sep 17 00:00:00 2001 From: Stefan Keim Date: Wed, 17 Dec 2025 10:41:27 +0100 Subject: [PATCH 1/4] Update extension.ts --- src/extension.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension.ts b/src/extension.ts index 8a6b04b..c8d86cb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -59,6 +59,7 @@ function registerNotebookController(context: vscode.ExtensionContext): void { 'python', 'mojo', "zig", + "powershell" ]; controller.executeHandler = ( From a8ba577652806394a44a07ade2210ea19741aa09 Mon Sep 17 00:00:00 2001 From: Stefan Keim Date: Wed, 17 Dec 2025 10:41:49 +0100 Subject: [PATCH 2/4] Update kernel.ts --- src/kernel.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/kernel.ts b/src/kernel.ts index 0ebdcde..54f18e3 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -17,6 +17,7 @@ import { processCellsTypescript } from './languages/typescript'; import { ChildProcessWithoutNullStreams, spawnSync, spawn } from 'child_process'; import { processShell as processShell } from './languages/shell'; import { processCellsPython } from './languages/python'; +import { processPowerShell } from './languages/powershell'; import * as vscode from 'vscode'; import { homedir } from 'os'; import { processCellsMojo } from './languages/mojo'; @@ -360,7 +361,16 @@ export class Kernel { } lastRunLanguage = 'shell'; const nuResult = processShell(currentCell, 'nushell'); - return { stream: nuResult.stream, clearOutput: nuResult.clearOutput }; + return { stream: nuResult.stream, clearOutput: nuResult.clearOutput } + + case 'powershell': + if (commandNotOnPath('powershell', 'https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell')) { + return null; + } + lastRunLanguage = 'powershell'; + const psResult = processPowerShell(currentCell); + return { stream: psResult.stream, clearOutput: psResult.clearOutput }; + default: return null; @@ -483,7 +493,8 @@ export class Kernel { buf = Buffer.concat(arr); const outputs = decoder.decode(buf).split(/!!output-start-cell[\n,""," "]/g); const currentCellOutput = - lastRunLanguage === 'shell' ? outputs[1] : outputs[currentCellLang.index]; + ['shell','powershell'].includes(lastRunLanguage) + ? outputs[1] : outputs[currentCellLang.index]; if (!clearOutput && currentCellOutput?.trim()) { exec.replaceOutput([ From 8dfbce7daf823ad258fef735f7dc5ff473d71a29 Mon Sep 17 00:00:00 2001 From: Stefan Keim Date: Wed, 17 Dec 2025 10:42:28 +0100 Subject: [PATCH 3/4] Create powershell.ts --- src/languages/powershell.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/languages/powershell.ts diff --git a/src/languages/powershell.ts b/src/languages/powershell.ts new file mode 100644 index 0000000..84e0005 --- /dev/null +++ b/src/languages/powershell.ts @@ -0,0 +1,35 @@ +import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; +import { writeFileSync, mkdirSync } from 'fs'; +import path from 'path'; +import { NotebookCell } from 'vscode'; +import { getTempPath } from '../config'; +import { LanguageCommand } from '../types'; + +const tempDir = getTempPath(); + +export const processPowerShell = ( + cell: NotebookCell +): { stream: ChildProcessWithoutNullStreams; clearOutput: boolean } => { + const prog = process.platform === 'win32' ? 'powershell' : 'pwsh'; + + const contents = cell.document.getText(); // optionally escape quotes + + const main = ` +Write-Host "!!output-start-cell" +& {${contents}} +`; + + const filename = path.join(tempDir, 'main.ps1'); + mkdirSync(tempDir, { recursive: true }); + writeFileSync(filename, main); + + let clearOutput = false; + if (cell.metadata?.command?.startsWith(LanguageCommand.clear)) { + clearOutput = true; + } + + return { + stream: spawn(prog, ['-NoProfile', '-File', filename], { cwd: tempDir }), + clearOutput, + }; +}; From 2ed710de9b5edeb24204b92e5cba7b3a4a6e272e Mon Sep 17 00:00:00 2001 From: Stefan Keim Date: Wed, 17 Dec 2025 10:43:02 +0100 Subject: [PATCH 4/4] Update markdownParser.ts --- src/markdownParser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/markdownParser.ts b/src/markdownParser.ts index 8775aec..ef99e23 100644 --- a/src/markdownParser.ts +++ b/src/markdownParser.ts @@ -23,6 +23,7 @@ export const LANG_IDS = new Map([ ['zsh', 'zsh'], ['openai', 'openai'], ['groq', 'groq'], + ['powershell', 'powershell'], ]); const LANG_ABBREVS = new Map(Array.from(LANG_IDS.keys()).map((k) => [LANG_IDS.get(k), k]));