Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

function libtmux-rs latest

escape_format

Escape text so tmux uses it as written rather than expanding it.

Source and package
Qualified name
libtmux::target::escape_format
Module
target
Package
libtmux
Source
crates/libtmux/src/target.rs
#[must_use] pub fn escape_format(text: impl AsRef<OsStr>) -> OsString

Description#

tmux runs its format machinery over more than names: #(command) runs command in a shell and #{session_id} becomes the id, in a session or window name and in the start directory -c names alike. Doubling # is what tmux's parser reads as one literal #, so the text arrives as itself -- which also makes a directory whose name really contains # reachable, where passing it through unescaped does not.

Every typed argument that tmux expands takes TmuxArg, which applies this on conversion, so a caller reaches for this directly only when building a raw crate::Command of their own.

Examples#

use std::ffi::OsString;
use libtmux::escape_format;
// Text that would otherwise run a command.
assert_eq!(escape_format("#(id)"), OsString::from("##(id)"));
// Ordinary text is unchanged.
assert_eq!(escape_format("editor"), OsString::from("editor"));
Parameters
Esc

Type to search.

Reference previewOpen reference