Crate opensesame

Crate opensesame 

Source
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

EditorBinaryLine:Column Support
VS Codecode
VS Code Insiderscode-insiders
VSCodiumcodium
Cursorcursor
Windsurfwindsurf
Vimvim
NeoVimnvim
Emacsemacs
Sublime Textsubl
Zedzed
Helixhx
Nanonano
TextMatemateLine only
Notepad++notepad++
JetBrains IDEsidea, webstorm, etc.Line only
XcodexedLine 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.
EditorBuilder
Builder for opening files in editors with fine-grained control.
EditorConfig
Configuration for editor selection.
EditorKindConfig
Wrapper for EditorKind that supports serde string deserialization.

Enums§

EditorKind
Known text editor types.
Error
Errors that can occur when opening files in editors.
ResolveFrom
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.