linutil
linutil copied to clipboard
fix: Respect shebangs in scripts
Type of Change
- [x] New feature
- [x] Bug fix
Description
I've brought back the changes from #247, since they heavily improve maintainability, especially of the core crate, which has major modifications in this PR. I've handled its merge conflicts.
The major change in this PR is that linutil core will now read the shebang from any script; the Command struct has been updated to include an executable and arguments in order to launch a script. In the case that a shebang isn't present, we'll return sh -e
, which is the shebang currently used in most scripts (though, before this PR, never actually being used to execute scripts; sh was called without arguments).
I've chosen to make the executable & arguments unique fields, as opposed to a single String, in order to simplify future additions, such as GUIs. Rust's std::process::Command
, as well as most libraries which have a Command struct, take in a command & a vector of arguments (including the one we're using for the TUI; we're only passing in a formatted String instead because of the addition of multi selection).
Testing
Scripts launch correctly, commands run match expectations.
Impact
Performance impact should be negligible, we're only reading the first 2 bytes of each script if no shebang is present, or until the first line break if it is. Scripts which require a certain shell or shell arguments will be executed as intended following this change.
Issues / other PRs related
- Resolves #489
Additional Information
Checklist
- [x] My code adheres to the coding and style guidelines of the project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [x] My changes generate no errors/warnings/merge conflicts.