linutil
linutil copied to clipboard
Add revertable commands
Pull Request
Title
Add revertable commands (competing with #384).
Type of Change
- [x] New feature
- [x] Refactoring
- [x] UI/UX improvement
Description
Revertable commands are added, and a database of commands which have previously been run is stored (in ~/.local/state/linutil_scripts.toml). At startup, the toml is read to determine which entries should be set to revert by default, and when a command (either normal or revert) is completed successfully, the appropriate data is written to the toml.
This is based upon the multi selection PR (#338), so the feature is fully implemented. Pressing 'r' inverts the entries shown (Revert -> Normal and vice versa). Scripts which don't support reversion have revertable = false
added to their tab data entry & function normally. When multi selection is enabled, pressing 'r' does not invert currently selected options.
This is also based upon #247, since the refactoring done there could otherwise cause merge conflicts. That pull request has no downsides and should be merged before this one regardless.
Implementation within scripts matches #384; revertable scripts have a run() and revert() function, and they're run by sourcing the script and running the appropriate function. Non revertable scripts (which are not possible in #384), are executed exactly the same way they were prior to these changes. Revertable scripts were implemented by @nnyyxxxx, the commits are fully intact and can be viewed within this PR.
UI example: https://github.com/user-attachments/assets/e773d71f-c410-4a29-b38b-a95b0133f6d4
Please reference https://github.com/ChrisTitusTech/linutil/pull/401#issuecomment-2351825078 and https://github.com/ChrisTitusTech/linutil/pull/401#issuecomment-2351828878 regarding accusations that I've "stolen" code. TLDR; the person making this accusation was not acting in good faith whatsoever and just wanted to shut down discussion.
Testing
Commands are correctly updated in the TOML & UI on next entry, reversion of scripts works correctly
Impact
The dirs
crate has been added as a dependency for linutil_core in order to fetch the preferred state directory (typically ~/.local/state) as well as possible. Another TOML is being read at startup & written to after successful command execution, which will slightly degrade performance.
Issue related to PR
- Resolves https://github.com/ChrisTitusTech/linutil/issues/240
- Resolves https://github.com/ChrisTitusTech/linutil/issues/260
- Resolves https://github.com/ChrisTitusTech/linutil/pull/362
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.