# target.escape_format

- **Module:** target
- **Package:** libtmux
- **Language:** Rust
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/target.rs#L40
- **Page:** https://libtmux.org/en/rs/latest/reference/target-escape_format/

```
target.escape_format(text: impl AsRef<OsStr>) -> OsString
```

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

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.

## Example

```rust
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"));
```
