dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.62k stars 66 forks source link

Environment variable integration #16

Closed dundalek closed 6 years ago

dundalek commented 6 years ago

As for now one can use the JS interop to access and set environment variables:

echo (str js/process.env.VAR_NAME)
;; or
echo (expand "$VAR_NAME")

;; change with
(aset js/process.env "VAR_NAME" value)

Maybe we want to introduce helper functions like (setenv) or (setenv!) and (getenv) ?

Another thing is setting an env variable only for the child process, alternative to bash: NODE_ENV=production npm start

mnewt commented 6 years ago

I created a pull request for (getenv) and (setenv). It seems omitting the '!' is the way you're going with other things. I agree with this, as it's cumbersome to type and this is a shell--lots of stuff is going to be mutable.

I think more needs to be done though. I haven't fully thought this through, but it seems closh will need shell local and exported (environment) variables just like other shells. Any thoughts on how to handle that?

As for setting an environment variable only for a child process, closh can do the same thing fish does and just rely on an external env command. E.g.

    $ env P=1 bash -c "echo $P"
    1

This works, but I can't help thinking there is a more elegant solution.

dundalek commented 6 years ago

I like the reasoning behind omitting the bang.

Sweet, that's a pretty nifty trick with the env command. I am glad it works so we don't need to add an additional function.

dundalek commented 6 years ago

Implemented in the PR