Skip to content

Commit 28cd2ff

Browse files
authored
New version 1.10.0
New version 1.10.0
2 parents f4fd48b + 4d6117f commit 28cd2ff

14 files changed

Lines changed: 105 additions & 15 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77

8+
## [Unreleased]
9+
### Added
10+
- Support for zig (Thanks to @slar)
11+
- Support for enabling WSL Mode for the shell language only (Thanks to @mihai-vlc)
12+
13+
### Changed
14+
- Update README.md
15+
16+
817
## [1.9.1]
918
### Changed
1019
- Fix bug produced by duplicate labeled code blocks (Thanks to @qiaogaojian)

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The result is shown only after the execution is finished. It is not possible to
1414
![Video that shows how the plugin works.](https://github.com/twibiral/obsidian-execute-code/blob/master/images/execute_code_example.gif?raw=true)
1515

1616

17-
The following [languages are supported](#supported-programming-languages-): C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell, Octave, and Maxima.
17+
The following [languages are supported](#supported-programming-languages-): C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell, Octave, Maxima and Zig.
1818

1919

2020
Python, Rust, and Octave support embedded plots. All languages support ["magic" commands](#magic-commands-) that help you to access paths in obsidian or show images in your notes.
@@ -23,6 +23,8 @@ You can create code blocks that are executed before or after each code block of
2323

2424
Take a look at the [changelog](CHANGELOG.md) to see what has changed in recent versions.
2525

26+
[Here](#misc-) you can find some other tools and plugins that might are compatible with this plugin and might be useful for you.
27+
2628
<div align='center'>
2729

2830
[![Buy us a coffee](https://img.shields.io/badge/-buy_us_a%C2%A0coffee-gray?logo=buy-me-a-coffee)](https://www.buymeacoffee.com/timwibiral)
@@ -627,9 +629,17 @@ undefined
627629
To manage the open runtimes for Notebook Mode, you can use the `Open Code Runtime Management` command in the command palette. From this sidebar window, you can stop kernels. **Note: force-stopping requires `taskkill` on Windows and `pkill` on Unix. 99% of systems should have these preinstalled: if yours doesn't, please [file an issue](https://github.com/twibiral/obsidian-execute-code/issues/new/choose)**
628630

629631

630-
## Style Settings 🎨
632+
## Misc 📦
633+
### Style Settings 🎨
634+
635+
This plugin supports customising styles using the [Style Settings plugin](https://github.com/mgmeyers/obsidian-style-settings)
636+
or the [Obsidian Code Styler plugin](https://github.com/mayurankv/Obsidian-Code-Styler).
637+
638+
### Other Tools
639+
640+
Take a look at the [Obsidian Tools python package](https://github.com/mfarragher/obsidiantools) to find some useful
641+
tools for interacting with your vault.
631642

632-
This plugin supports customising styles using the [Style Settings plugin](https://github.com/mgmeyers/obsidian-style-settings). It's possible to customise the color of code block outputs and errors.
633643

634644
## Installation 💾
635645

esbuild.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ esbuild.build({
4848
logLevel: "info",
4949
sourcemap: prod ? false : 'inline',
5050
treeShaking: true,
51-
outfile: 'src/main.js',
51+
outfile: 'main.js',
5252
}).catch(() => process.exit(1));

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "execute-code",
33
"name": "Execute Code",
4-
"version": "1.9.1",
4+
"version": "1.10.0",
55
"minAppVersion": "1.2.8",
66
"description": "Allows to execute code snippets within a note. Supported programming languages: C, CPP, Dart, Golang, Groovy, Kotlin, Java, JavaScript, TypeScript, Lean, Lua, CSharp, Prolog, Rust, Python, R, Ruby, Wolfram Mathematica, Haskell, Scala, Racket, F#, Batch, Shell & Powershell.",
77
"author": "twibiral",

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "execute-code",
3-
"version": "1.9.1",
3+
"version": "1.10.0",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "src/main.js",
66
"scripts": {

src/executors/NonInteractiveCodeExecutor.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import Executor from "./Executor";
55
import {Outputter} from "src/Outputter";
66
import {LanguageId} from "src/main";
77
import { ExecutorSettings } from "../settings/Settings.js";
8-
import { sep } from "path";
9-
import { join } from "path/posix";
108
import windowsPathToWsl from "../transforms/windowsPathToWsl.js";
119

1210
export default class NonInteractiveCodeExecutor extends Executor {
@@ -38,13 +36,13 @@ export default class NonInteractiveCodeExecutor extends Executor {
3836

3937
fs.promises.writeFile(tempFileName, codeBlockContent).then(() => {
4038
const args = cmdArgs ? cmdArgs.split(" ") : [];
41-
42-
if (this.settings.wslMode) {
39+
40+
if (this.isWSLEnabled()) {
4341
args.unshift("-e", cmd);
4442
cmd = "wsl";
4543
args.push(windowsPathToWsl(tempFileName));
4644
} else {
47-
args.push(tempFileName);
45+
args.push(tempFileName);
4846
}
4947

5048
const child = child_process.spawn(cmd, args, {env: process.env, shell: this.usesShell});
@@ -63,6 +61,18 @@ export default class NonInteractiveCodeExecutor extends Executor {
6361
});
6462
}
6563

64+
private isWSLEnabled(): boolean {
65+
if (this.settings.wslMode) {
66+
return true;
67+
}
68+
69+
if (this.language == 'shell' && this.settings.shellWSLMode) {
70+
return true;
71+
}
72+
73+
return false;
74+
}
75+
6676
/**
6777
* Handles the output of a child process and redirects stdout and stderr to the given {@link Outputter} element.
6878
* Removes the temporary file after the code execution. Creates a new Notice after the code execution.

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import runAllCodeBlocks from './runAllCodeBlocks';
2626
export const languageAliases = ["javascript", "typescript", "bash", "csharp", "wolfram", "nb", "wl", "hs", "py", "scpt"] as const;
2727
export const canonicalLanguages = ["js", "ts", "cs", "lean", "lua", "python", "cpp", "prolog", "shell", "groovy", "r",
2828
"go", "rust", "java", "powershell", "kotlin", "mathematica", "haskell", "scala", "racket", "fsharp", "c", "dart",
29-
"ruby", "batch", "sql", "octave", "maxima", "applescript"] as const;
29+
"ruby", "batch", "sql", "octave", "maxima", "applescript", "zig"] as const;
3030
export const supportedLanguages = [...languageAliases, ...canonicalLanguages] as const;
3131
export type LanguageId = typeof canonicalLanguages[number];
3232

@@ -397,6 +397,12 @@ export default class ExecuteCodePlugin extends Plugin {
397397
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
398398
this.runCodeInShell(transformedCode, out, button, this.settings.applescriptPath, this.settings.applescriptArgs, this.settings.applescriptFileExtension, language, file);
399399
})
400+
} else if (language === "zig") {
401+
button.addEventListener("click", async () => {
402+
button.className = runButtonDisabledClass;
403+
const transformedCode = await new CodeInjector(this.app, this.settings, language).injectCode(srcCode);
404+
this.runCodeInShell(transformedCode, out, button, this.settings.zigPath, this.settings.zigArgs, "zig", language, file);
405+
})
400406
}
401407

402408
}

src/settings/Settings.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ExecutorSettings {
99
timeout: number;
1010
allowInput: boolean;
1111
wslMode: boolean;
12+
shellWSLMode: boolean;
1213
onlyCurrentBlock: boolean;
1314
nodePath: string;
1415
nodeArgs: string;
@@ -128,6 +129,9 @@ export interface ExecutorSettings {
128129
applescriptArgs: string;
129130
applescriptFileExtension: string;
130131
applescriptInject: string;
132+
zigPath: string;
133+
zigArgs: string;
134+
zigInject: string;
131135

132136
jsInteractive: boolean;
133137
tsInteractive: boolean;
@@ -159,6 +163,7 @@ export interface ExecutorSettings {
159163
octaveInteractive: boolean;
160164
maximaInteractive: boolean;
161165
applescriptInteractive: boolean;
166+
zigInteractive: boolean;
162167
}
163168

164169

@@ -171,6 +176,7 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
171176
timeout: 10000,
172177
allowInput: true,
173178
wslMode: false,
179+
shellWSLMode: false,
174180
onlyCurrentBlock: false,
175181
nodePath: "node",
176182
nodeArgs: "",
@@ -290,6 +296,9 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
290296
applescriptArgs: "",
291297
applescriptFileExtension: "scpt",
292298
applescriptInject: "",
299+
zigPath: "zig",
300+
zigArgs: "run",
301+
zigInject: "",
293302
jsInteractive: true,
294303
tsInteractive: false,
295304
csInteractive: false,
@@ -320,4 +329,5 @@ export const DEFAULT_SETTINGS: ExecutorSettings = {
320329
octaveInteractive: false,
321330
maximaInteractive: false,
322331
applescriptInteractive: false,
332+
zigInteractive: false,
323333
}

src/settings/SettingsTab.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import makeSQLSettings from "./per-lang/makeSQLSettings";
3131
import makeOctaviaSettings from "./per-lang/makeOctaveSettings";
3232
import makeMaximaSettings from "./per-lang/makeMaximaSettings";
3333
import makeApplescriptSettings from "./per-lang/makeApplescriptSettings";
34+
import makeZigSettings from "./per-lang/makeZigSettings";
3435

3536

3637
/**
@@ -218,6 +219,9 @@ export class SettingsTab extends PluginSettingTab {
218219
// ========== Applescript ============
219220
makeApplescriptSettings(this, this.makeContainerFor("applescript"));
220221

222+
// ========== Zig ============
223+
makeZigSettings(this, this.makeContainerFor("zig"));
224+
221225
this.focusContainer(this.plugin.settings.lastOpenLanguageTab || canonicalLanguages[0]);
222226
}
223227

0 commit comments

Comments
 (0)