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

Commit a6d7ae1

Browse files
committed
Passes in current file as arg
1 parent 4a7991e commit a6d7ae1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

main.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,34 @@ export default class PythonScripterPlugin extends Plugin {
5757
const obsidianCommand = {
5858
id: "run-"+files[index],
5959
name: 'Run '+files[index],
60-
callback: () => {
60+
callback: (editor: Editor) => {
6161
fs.stat(filePath, (err: any, stats: { isFile: () => any; isDirectory: () => any; }) => {
6262
if (err) {
6363
console.error(err);
6464
return;
6565
}
6666
if (stats.isFile()) {
67-
exec(`python ${filePath} ${basePath}`, {cwd: this.pythonDirectory}, (error: any, stdout: any, stderr: any) => {
67+
var local_current_file_path = this.app.workspace.activeEditor?.file?.path;
68+
if (local_current_file_path === undefined) {
69+
local_current_file_path = "";
70+
}
71+
var abs_current_file_path = path.join(basePath, local_current_file_path);
72+
exec(`python ${filePath} ${basePath} ${abs_current_file_path}`, {cwd: this.pythonDirectory}, (error: any, stdout: any, stderr: any) => {
6873
if (error) {
6974
new Notice(`Error executing script ${filePath}: ${error}`);
7075
return;
7176
}
72-
7377
new Notice(`Script ` + fileName + ` output:\n${stdout}`);
7478
});
7579
} else if (stats.isDirectory()) {
7680
var dir = path.join(filePath);
7781
var executable = path.join(".", filePath, "src", "main.py");
78-
exec(`python ${executable} ${basePath}`, {cwd: dir}, (error: any, stdout: any, stderr: any) => {
82+
var local_current_file_path = this.app.workspace.activeEditor?.file?.path;
83+
if (local_current_file_path === undefined) {
84+
local_current_file_path = "";
85+
}
86+
var abs_current_file_path = path.join(basePath, local_current_file_path);
87+
exec(`python ${executable} ${basePath} ${abs_current_file_path}`, {cwd: dir}, (error: any, stdout: any, stderr: any) => {
7988
if (error) {
8089
new Notice(`Error executing folder program: ${error}`);
8190
return;

0 commit comments

Comments
 (0)