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

Commit 24fe0a8

Browse files
committed
Merge branch 'rewrite'
2 parents c470a5b + 83410a9 commit 24fe0a8

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

src/managers/scriptManager.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export class ScriptManager {
5454
}
5555

5656
let scriptStartTime = Date.now();
57+
if (scriptConfig.runDirectory) {
58+
basePath = path.join(basePath, scriptConfig.runDirectory);
59+
}
60+
process.chdir(basePath);
61+
console.log(`Running script: ${cmd} from ${basePath}`);
5762
exec(cmd, (error, stdout, stderr) => {
5863
// Handle output based on scriptConfig.output
5964
if (scriptConfig.output?.type === 'notice') {
@@ -117,8 +122,6 @@ export class ScriptManager {
117122

118123
private isExecutable(filePath: string): boolean {
119124
try {
120-
// Check if the file exists
121-
fs.accessSync(filePath, fs.constants.F_OK);
122125
// On Windows, check if the file has an executable extension
123126
if (process.platform === 'win32') {
124127
const executableExtensions = ['.exe', '.bat', '.cmd'];
@@ -128,8 +131,10 @@ export class ScriptManager {
128131
return false;
129132
}
130133
}
131-
// Check if the file is executable
132-
fs.accessSync(filePath, fs.constants.X_OK);
134+
if (process.platform !== 'win32') {
135+
// On Unix-based systems, check if the file has the executable permission
136+
fs.accessSync(filePath, fs.constants.F_OK | fs.constants.X_OK);
137+
}
133138
return true;
134139
} catch (error) {
135140
// If the file doesn't exist, check if it's in the PATH

src/modals/scriptSettingsModal.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ export class ScriptSettingsModal extends Modal {
2626
contentEl.empty(); // Clear the modal content
2727
contentEl.createEl('h2', { text: `Settings for ${this.scriptPath}` });
2828

29+
// Run Directory setting
30+
new Setting(contentEl)
31+
.setName('Run Directory')
32+
.setDesc('Specify the directory relative to the vault root to run the script in. (Defaults to the vault root directory)')
33+
.addText(text => {
34+
text.setValue(this.scriptConfig.runDirectory || '')
35+
.onChange(value => {
36+
this.scriptConfig.runDirectory = value;
37+
});
38+
});
39+
2940
// Interpreter setting
3041
new Setting(contentEl)
3142
.setName('Interpreter')

src/settings/scriptSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// src/settings/scriptSettings.ts
22
export interface ScriptSettings {
33
interpreter?: string;
4+
runDirectory?: string; // Directory to run the script in
45
arguments?: {
56
currentFile?: boolean; // Include current file path
67
vaultPath?: boolean; // Include vault path

src/settings/scriptSettingsTab.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export class ScriptSettingsTab extends PluginSettingTab {
4545
// Convert absolute paths to relative paths from scripts folder
4646
return file.replace(scriptsFolder + "/", "");
4747
});
48+
49+
// cut all .git folders
50+
items.folders = items.folders.filter((folder) => !folder.includes('.git'));
4851

4952
// Recursively process subdirectories
5053
for (const folder of items.folders) {

yarn.lock

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818
style-mod "^4.1.0"
1919
w3c-keyname "^2.2.4"
2020

21-
"@esbuild/darwin-arm64@0.17.3":
21+
"@esbuild/linux-x64@0.17.3":
2222
version "0.17.3"
23-
resolved "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.3.tgz"
24-
integrity sha512-01Hxaaat6m0Xp9AXGM8mjFtqqwDjzlMP0eQq9zll9U85ttVALGCGDuEvra5Feu/NbP5AEP1MaopPwzsTcUq1cw==
23+
resolved "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.3.tgz"
24+
integrity sha512-0AGkWQMzeoeAtXQRNB3s4J1/T2XbigM2/Mn2yU1tQSmQRmHIZdkGbVq2A3aDdNslPyhb9/lH0S5GMTZ4xsjBqg==
25+
26+
"@esbuild/[email protected]":
27+
version "0.17.3"
28+
resolved "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.3.tgz"
29+
integrity sha512-FdVl64OIuiKjgXBjwZaJLKp0eaEckifbhn10dXWhysMJkWblg3OEEGKSIyhiD5RSgAya8WzP3DNkngtIg3Nt7g==
2530

2631
"@eslint-community/eslint-utils@^4.2.0":
2732
version "4.4.1"

0 commit comments

Comments
 (0)