Execute Scripts on Startup
When starting Ocular, you can choose to have scripts automatically executed.
Executing Scripts for a Specific Session
You can execute initialization scripts for a specific session
As an example, let's say that you have a script, myScript1.sc, with the following contents:
echo 'def foo = 42' > scripts/myScript1.sc
Start Ocular using sl ocular
, load your CPG, and use the runScript
command:
cpg.runScript("scripts/myScript1.sc")
You'll see the following responses as Ocular runs your script:
ocular> foo
res0: Int = 42
Executing Scripts for all Sessions
To execute initialization code every time you start Ocular, write it to a .sc file in your ~/.shiftleft/ocular directory. We recommend calling your file predef.sc, but by default, Ocular executes all of the files with the .sc extension in that directory whenever it starts.
As an example, let's say that you've created your predef.sc file as follows:
echo 'def foo = 42' > ~/.shiftleft/ocular/predef.sc
Start Ocular using sl ocular
. You'll see the results of the file having been run:
ocular> foo
res0: Int = 42