matklad / xshell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement `Clone` for `Shell`?

bzm3r opened this issue · comments

There are two fundamental parts to an xshell::Shell: https://docs.rs/xshell/latest/src/xshell/lib.rs.html#383

Both cwd and env have T in RefCell<T> that can be cloned, so a "deep clone" (not a RefCell clone) could be implemented for Shell. It would be useful to do this in order to create "related" shells (e.g. nix style development shells) from a current shell.

cwd can already be reported via current_dir, and PR #78 aims to expose similar functionality for env. Therefore, it would be possible to create a new shell (Shell::new()) that is a clone of an existing shell by setting its current working directory and environment variables appropriately using set_var (based on the output of the proposed vars_os method on the original shell).

So, implementing Clone would provide this functionality in an idiomatic form?