2

I'm trying to minimize the amount of boilerplate that I have to write in an ammonite script. It seems like predef.sc is not loaded by default (which is good) but I'd like to have different sets of predefs for different files, and simply write a line to load them.

It seems like there's no way to refer to / or $HOME without importing ammonite-shell (which in turn requires you to use import $ivy/interp.load.ivy which means at least 3-4 lines in total). Using relative paths ($file.^.somefolder.somefile) works but relative paths break too easily.

So hence the question - is there a one-liner to load a script relative to root or $HOME? something like

$exec $file.`$HOME`.path.to.somefile
Jacob Wang
  • 4,411
  • 5
  • 29
  • 43

1 Answers1

1

I think import $exec.file is the same as repl.load.exec so you would do something like:

repl.load.exec(Path("/abs/path/to/file.sc"))
  • 1
    What is "repl" in your answer. It does not appear to be a package or object that can be imported in ammonite. `ammonite.repl` does not have a `load` subpackage, etc. – ely Aug 27 '18 at 15:29
  • @ely 'repl' is a object that is available in Ammonite by default. You can see usages for it like 'repl.history', 'repl.width' etc... from the documentation here: http://ammonite.io/#ReplAPI. The 'repl.load' command can also be found on this page. – Choppy The Lumberjack Aug 29 '18 at 06:30
  • I get an error when I try `repl.load` in ammonite: `cmd1.sc:1: value load is not a member of ammonite.repl.FullReplAPI` (using version 0.8.2). – ely Aug 29 '18 at 12:21