@@ -338,17 +338,32 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
338
338
return fmt .Errorf ("chat UI only supports files, cannot read from stdin" )
339
339
}
340
340
341
- absPathToScript , err := filepath .Abs (args [1 ])
342
- if err != nil {
343
- return fmt .Errorf ("cannot determine absolute path to script %s: %v" , args [1 ], err )
341
+ file := args [1 ]
342
+
343
+ // If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
344
+ // set it to the directory of the script and set the file to the base.
345
+ external := strings .HasPrefix (file , "http://" ) || strings .HasPrefix (file , "https://" ) || strings .HasPrefix (file , "github.com" )
346
+ if ! external {
347
+ absPathToScript , err := filepath .Abs (args [1 ])
348
+ if err != nil {
349
+ return fmt .Errorf ("cannot determine absolute path to script %s: %v" , args [1 ], err )
350
+ }
351
+ gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + filepath .Dir (absPathToScript ))
352
+ file = filepath .Base (args [1 ])
353
+ } else {
354
+ cwd , err := os .Getwd ()
355
+ if err != nil {
356
+ return fmt .Errorf ("could not determine current working directory: %w" , err )
357
+ }
358
+ gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + cwd )
344
359
}
345
360
346
- gptOpt .Env = append (gptOpt .Env , "SCRIPTS_PATH=" + filepath .Dir (absPathToScript ))
347
361
if os .Getenv (system .BinEnvVar ) == "" {
348
362
gptOpt .Env = append (gptOpt .Env , system .BinEnvVar + "=" + system .Bin ())
349
363
}
350
364
351
- args = append ([]string {args [0 ]}, "--file=" + filepath .Base (args [1 ]))
365
+ args = append ([]string {args [0 ]}, "--file=" + file )
366
+
352
367
if len (args ) > 2 {
353
368
args = append (args , args [2 :]... )
354
369
}
0 commit comments