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

Commit 287c795

Browse files
committed
Fixed paths with spaces in them
1 parent 5bde406 commit 287c795

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/managers/scriptManager.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ export class ScriptManager {
2828
// Replace any unescaped quotes with escaped quotes
2929
return `"${arg.replace(/"/g, '\\"')}"`;
3030
});
31-
31+
32+
// Quote the script path to handle spaces
33+
const quotedScriptPath = `"${scriptPath}"`;
34+
3235
let cmd = scriptConfig.interpreter
33-
? `${scriptConfig.interpreter} ${scriptPath} ${escapedArgs.join(' ')}`
34-
: `${scriptPath} ${escapedArgs.join(' ')}`;
35-
36+
? `"${scriptConfig.interpreter}" ${quotedScriptPath} ${escapedArgs.join(' ')}`
37+
: `${quotedScriptPath} ${escapedArgs.join(' ')}`;
38+
3639
// check if command is executable
3740
this.plugin.log(`Running script: ${scriptPath}, with interpreter: ${interpreter}`, 'verbose');
3841
if (!this.isRunnable(interpreter, scriptPath)) {
@@ -45,11 +48,11 @@ export class ScriptManager {
4548
}
4649
return;
4750
}
48-
51+
4952
if (this.settings.verbosity === 'verbose') {
5053
this.plugin.log(`Executing command: ${cmd}`, 'verbose');
5154
}
52-
55+
5356
let scriptStartTime = Date.now();
5457
exec(cmd, (error, stdout, stderr) => {
5558
// Handle output based on scriptConfig.output
@@ -65,13 +68,13 @@ export class ScriptManager {
6568
}
6669
}
6770
}
68-
71+
6972
// Handle errors
7073
if (error) {
7174
new Notice('Error executing script.', 5000);
7275
this.plugin.log('Error executing script:', "silent");
7376
}
74-
77+
7578
const scriptEndTime = Date.now();
7679
const scriptDuration = scriptEndTime - scriptStartTime;
7780
new Notice(`Script executed successfully (took ${scriptDuration} ms), output: ${stdout}`, 5000);

src/settings/scriptSettingsTab.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ScriptSettingsTab extends PluginSettingTab {
1515

1616
// Method to list scripts in the directory
1717
async listScripts(): Promise<string[]> {
18-
const scriptsFolder = path.join(this.plugin.app.vault.configDir, this.plugin.settings.scriptsFolder);
18+
const scriptsFolder = path.join(this.plugin.settings.scriptsFolder);
1919
// if the directory is an absolute path, print an error and return an empty array
2020
if (path.isAbsolute(this.plugin.settings.scriptsFolder)) {
2121
this.plugin.log(`Scripts directory path is absolute: ${this.plugin.settings.scriptsFolder}, change to local path`, 'silent');
@@ -26,6 +26,8 @@ export class ScriptSettingsTab extends PluginSettingTab {
2626
const items = await this.listFilesRecursive(scriptsFolder);
2727
return items;
2828
} catch (error) {
29+
this.plugin.log(`Scripts directory: ${scriptsFolder}`, 'verbose');
30+
2931
this.plugin.log(`Error reading directory: ${error}`, 'silent');
3032
return [];
3133
}
@@ -34,7 +36,8 @@ export class ScriptSettingsTab extends PluginSettingTab {
3436
async listFilesRecursive(dir: string): Promise<string[]> {
3537
try {
3638
let results: string[] = [];
37-
const items = await this.plugin.app.vault.adapter.list(dir);
39+
let dir_spaces_escaped = dir.replace(" ", "\ ");
40+
const items = await this.plugin.app.vault.adapter.list(dir_spaces_escaped);
3841
const scriptsFolder = path.join(this.plugin.app.vault.configDir, this.plugin.settings.scriptsFolder);
3942

4043
// Add all files from current directory

0 commit comments

Comments
 (0)