mitnk / cicada

An old-school bash-like Unix shell written in Rust
https://hugo.wang/cicada/
MIT License
981 stars 50 forks source link

implement 'source' builtin command #18

Closed ngklingler closed 5 years ago

ngklingler commented 5 years ago

Hey,

I noticed your shell does not have the source command as one of its builtins, which lets you source rc files during a session. It works like this: make a change to ~/.cicadarc, run source ~/.cicadarc, and any changes you made to your RC file will then be loaded. I was a pretty simple implementation, I just had to call the load_file function in the rcfile module. I hope you will incorporate this into your project.

mitnk commented 5 years ago

Hi @ngklingler, Thanks for the PR.

The source builtin should be more capable than just loading rcfile. It should also run cicada scripts (which is not supported yet, see the two big todo in readme).

But reloading refile is a useful feature. We can merge this PR with the following adjust:

  1. Check the input file, if it ends with "cicadarc", then reload the rc, otherwise, we print a hint that "scripting in cicada is still work in progress".

  2. Can you add source into src/completers/path.rs around line 168. So cicada completion knows this new builtin.

  3. Also a small item in Changelog would be great.

ngklingler commented 5 years ago

Hey @mitnk

Good call on those points. I changed the source commmand to check that the specified file ends in "cicadarc" if it does, we load the file; if it doesn't then it throws an error that only loading from cicadarc files is supported and scripting is a WIP. I added the source command to the completer, and I updated the changelog to mark this change. Let me know if anything else should be done.

mitnk commented 5 years ago

Looks great! Thanks again!