jupyterlite / cockle

In-browser bash-like shell implemented in TypeScript.
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Support environment variables that persist beyond single commands #10

Closed ianthomas23 closed 3 months ago

ianthomas23 commented 3 months ago

This PR adds a new Environment class that is a collection of environment variables that are owned by the Shell. These are copied into an individual WASM command's environment before the command is run, and changes are copied back out again afterwards. The copying in occurs in the preRun callback of the WASM module's constructor, which is a better place for the file system setting up so that is moved there as well.

Persistent environment variables are also required for builtin commands. A good example (the only builtin command so far) is cd which stores the current working directory in the PWD envvar and this is explicitly tested in a new test.