Expand description
§opensesame
A cross-platform Rust library for opening files in text editors with support for line and column positioning.
§Features
- Cross-platform: Works on macOS, Linux, and Windows
- Smart editor detection: Finds editors via
$VISUAL,$EDITOR, or PATH - Line:column positioning: Opens files at specific locations when supported
- Comprehensive editor support: VS Code, Vim, NeoVim, Emacs, Sublime Text, Zed, Helix, Nano, Cursor, Windsurf, JetBrains IDEs, Notepad++, and more
- Ergonomic API: Builder pattern for flexible configuration
- Type-safe errors: Rich error types for proper error handling
§Quick Start
use opensesame::Editor;
// Open a file in the default editor
Editor::open("src/main.rs")?;
// Open at a specific line
Editor::open_at("src/main.rs", 42)?;
// Open at a specific line and column
Editor::open_at_position("src/main.rs", 42, 10)?;§Builder API
For more control, use the builder pattern:
use opensesame::Editor;
Editor::builder()
.file("src/main.rs")
.line(42)
.column(10)
.wait(true) // Wait for editor to close
.open()?;§Specifying an Editor
You can specify which editor to use:
use opensesame::{Editor, EditorKind};
// Use a specific editor
Editor::builder()
.file("src/main.rs")
.editor(EditorKind::VsCode)
.line(42)
.open()?;
// Or by binary name
Editor::builder()
.file("src/main.rs")
.editor_binary("nvim")
.line(42)
.open()?;§Supported Editors
| Editor | Binary | Line:Column Support |
|---|---|---|
| VS Code | code | ✓ |
| VS Code Insiders | code-insiders | ✓ |
| VSCodium | codium | ✓ |
| Cursor | cursor | ✓ |
| Windsurf | windsurf | ✓ |
| Vim | vim | ✓ |
| NeoVim | nvim | ✓ |
| Emacs | emacs | ✓ |
| Sublime Text | subl | ✓ |
| Zed | zed | ✓ |
| Helix | hx | ✓ |
| Nano | nano | ✓ |
| TextMate | mate | Line only |
| Notepad++ | notepad++ | ✓ |
| JetBrains IDEs | idea, webstorm, etc. | Line only |
| Xcode | xed | Line only |
§Configuration
Applications can pass editor configuration to opensesame:
use opensesame::{Editor, EditorConfig};
let config = EditorConfig {
editor: Some("nvim".to_string()),
args: vec!["--noplugin".to_string()],
..Default::default()
};
Editor::builder()
.file("src/main.rs")
.with_config(config)
.open()?;§Custom Resolution Order
Control how editors are detected:
use opensesame::{Editor, ResolveFrom};
// Ignore config, only use environment variables
Editor::builder()
.file("src/main.rs")
.resolve_order(&[ResolveFrom::Visual, ResolveFrom::Editor])
.open()?;§Serde Support
Enable the serde feature for config file deserialization:
[dependencies]
opensesame = { version = "0.1", features = ["serde"] }Structs§
- Editor
- Main entry point for opening files in editors.
- Editor
Builder - Builder for opening files in editors with fine-grained control.
- Editor
Config - Configuration for editor selection.
- Editor
Kind Config - Wrapper for
EditorKindthat supports serde string deserialization.
Enums§
- Editor
Kind - Known text editor types.
- Error
- Errors that can occur when opening files in editors.
- Resolve
From - Sources from which an editor can be resolved.
Constants§
- DEFAULT_
RESOLVE_ ORDER - Default resolution order when configs are provided.
- ENV_
ONLY_ RESOLVE_ ORDER - Resolution order that ignores config (matches legacy behavior).
Type Aliases§
- Result
- A specialized Result type for opensesame operations.