@@ -57,25 +57,34 @@ export default class PythonScripterPlugin extends Plugin {
57
57
const obsidianCommand = {
58
58
id : "run-" + files [ index ] ,
59
59
name : 'Run ' + files [ index ] ,
60
- callback : ( ) => {
60
+ callback : ( editor : Editor ) => {
61
61
fs . stat ( filePath , ( err : any , stats : { isFile : ( ) => any ; isDirectory : ( ) => any ; } ) => {
62
62
if ( err ) {
63
63
console . error ( err ) ;
64
64
return ;
65
65
}
66
66
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 ) => {
68
73
if ( error ) {
69
74
new Notice ( `Error executing script ${ filePath } : ${ error } ` ) ;
70
75
return ;
71
76
}
72
-
73
77
new Notice ( `Script ` + fileName + ` output:\n${ stdout } ` ) ;
74
78
} ) ;
75
79
} else if ( stats . isDirectory ( ) ) {
76
80
var dir = path . join ( filePath ) ;
77
81
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 ) => {
79
88
if ( error ) {
80
89
new Notice ( `Error executing folder program: ${ error } ` ) ;
81
90
return ;
0 commit comments