https://github.com/spenserblack/find-editor.rs
Finds and opens an editor to edit a file. Useful if you want to make it easy for your users to edit config files.
https://github.com/spenserblack/find-editor.rs
cli cross-platform editor notepad open-editor rust vim
Last synced: 5 months ago
JSON representation
Finds and opens an editor to edit a file. Useful if you want to make it easy for your users to edit config files.
- Host: GitHub
- URL: https://github.com/spenserblack/find-editor.rs
- Owner: spenserblack
- License: apache-2.0
- Created: 2025-12-03T17:50:40.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-05T01:14:56.000Z (7 months ago)
- Last Synced: 2025-12-08T08:43:10.554Z (6 months ago)
- Topics: cli, cross-platform, editor, notepad, open-editor, rust, vim
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# find-editor.rs
[](https://crates.io/crates/find-editor)
Finds and opens an editor to edit a file. Useful if you want to make it easy for your
users to edit config files.
## Usage
You can find runnable examples in [`examples/`](./examples).
```rust
use find_editor::Finder;
let finder = Finder::with_extra_environment_variables(["MY_TOOL_EDITOR"]);
// Get an editor value
let editor = finder.editor_name();
println!("The raw editor command is: {editor}");
// Parse the editor string and assert it's on $PATH
let (editor_command, editor_args) = finder.which_editor().unwrap();
println!("The editor command is {editor_command:?} with the arguments {editor_args:?}");
// Open an editor on a file
finder.open_editor("config.toml", true).unwrap();
```
### Optional features
- `split`: Sometimes editors are not only a command name, but also a list of arguments
to pass to the command. `code --wait` is a common example. This feature provides
`split_editor_name`, which helps split an editor's text into the command and any
arguments.
- `which`: This provides `which_editor`, which will split the editor (see feature
`split`), and then find the command on `$PATH`. This helps assert that the command
is callable. Also, Windows will run executables in the current directory when running
a command. `which_editor` helps prevent that possible security issue by *only* finding
executables on `$PATH`.
- `open`: This provides the `open_editor` function. `which_editor` (see feature `which`)
and `split_editor_name` are both used to ensure that the editor is safely executed.