Pass Julia arguments to be executed in REPL?
Asked Answered
U

2

6

I very (very!) often do this routine in my daily work:

$ j7 # (alias for Julia version 1.7)
julia>
julia> ] activate .
(or similarly) (@v1.8) pkg> activate . 
Activating project at `~/MyMWE_WorkingPath`
julia> using Revise ; using RRSP # RRSP is my working module

I would like to have an alias for doing this routine quicker and easilier. I do it at the very least ten times a week and will do it for months more.

Ideally, I would do something like, j7RRSP which is an alias for:

alias j7RRSP='julia > ]activate . ; using Revise ; using RRSP'

This is incorrect and I don't know how to do it well! I know alias for executing julia files are possible :

alias j7jl='julia somefiles.jl'

In my case, I am activating a project then using two packages, Revise, which is standard, then RRSP that I created.

Utter answered 9/12, 2022 at 11:13 Comment(1)
Quick answer: you are looking to customize your startup.jl file and also for the --project option for julia command.Fluoresce
T
7

Another solution is using a function that works exactly like an alias, but with a much saner syntax and capabilities:

j7RRSP() {
  julia --project=. -e "using Revise, RRSP" -i "$@"
}

As a one-line:

j7RRSP(){ julia --project=. -e "using Revise, RRSP" -i "$@";}
Thordis answered 9/12, 2022 at 12:55 Comment(0)
R
9

Here is one solution:

alias j7RRSP='julia --project=. -e "using Revise, RRSP" -i'

Flags:

  • --project=.: start with the project in the current directory directly instead of using ]activate .,
  • -e "...": evaluate the code ...,
  • -i: ask for an interactive session, this is needed since otherwise, due to combining with -e, the process exits after evaluating the code.
Reiter answered 9/12, 2022 at 11:51 Comment(0)
T
7

Another solution is using a function that works exactly like an alias, but with a much saner syntax and capabilities:

j7RRSP() {
  julia --project=. -e "using Revise, RRSP" -i "$@"
}

As a one-line:

j7RRSP(){ julia --project=. -e "using Revise, RRSP" -i "$@";}
Thordis answered 9/12, 2022 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.