|
| 1 | +# Quoting Pitfalls in Plugin Variable Assignments |
| 2 | + |
| 3 | +## `$HOME`, `~`, and Single Quotes |
| 4 | + |
| 5 | +A common but problematic habit is using single quotes when assigning plugin variables, |
| 6 | +especially with paths involving `$HOME` or `~`. |
| 7 | + |
| 8 | +Before tmux 3.0, tmux would automatically interpret paths like `'$HOME/some/path'` |
| 9 | +or `'~/some/path'` correctly—effectively converting them to `"$HOME/some/path"` |
| 10 | +behind the scenes. |
| 11 | + |
| 12 | +That changed starting with version 3.0: |
| 13 | + |
| 14 | +- `'$HOME/some/path'` is interpreted as `"\$HOME/some/path"` |
| 15 | +- `'~/some/path'` becomes `\~/some/path` |
| 16 | + |
| 17 | +In 3.4, `$HOME` became `"\\$HOME/some/path"` while `~` was still broken in the same way. |
| 18 | +As of 3.5, tmux reverted to the 3.0 behavior again. |
| 19 | + |
| 20 | +To work around this inconsistency, a helper—`fix_home_path()`—has been added. |
| 21 | +It detects the tmux version and rewrites broken single-quoted paths into their |
| 22 | +proper double-quoted form. |
| 23 | + |
| 24 | +While this provides some compatibility, **it’s still discouraged**. Most plugins |
| 25 | +do not account for these quirks, and relying on single quotes leads to broken |
| 26 | +behavior across versions. |
| 27 | + |
| 28 | +**Best practice:** Always wrap paths and variables like `$HOME` or `~` in |
| 29 | +double quotes. This ensures consistent, correct expansion in all tmux versions. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## Special Characters and Escaping |
| 34 | + |
| 35 | +Quoting also affects how special characters like the backslash (`\`) are parsed. |
| 36 | + |
| 37 | +- With no quoting, `\\` must be used |
| 38 | +- In _single quotes_, both `'\\'` and `'\'` can be used. |
| 39 | +- In _double quotes_, you must escape the backslash: `"\\"`. |
| 40 | + |
| 41 | +To avoid subtle quoting issues in key bindings or option values, |
| 42 | +**escape special characters consistently**, regardless of quoting style: |
| 43 | + |
| 44 | +- Use `\\` for a literal backslash |
| 45 | +- Avoid switching between single and double quotes unless necessary |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Examples |
| 50 | + |
| 51 | +**Incorrect (common mistakes):** |
| 52 | + |
| 53 | +```tmux |
| 54 | +set -g @plugin_path '$HOME/.tmux/plugins' |
| 55 | +set -g @plugin_path '~/plugins' |
| 56 | +set -g @my_key '\' # unreliable in some quoting contexts |
| 57 | +``` |
| 58 | + |
| 59 | +**Correct (portable and safe):** |
| 60 | + |
| 61 | +```tmux |
| 62 | +set -g @plugin_path "$HOME/.tmux/plugins" |
| 63 | +set -g @plugin_path "$HOME/plugins" |
| 64 | +set -g @my_key "\\" # explicit and unambiguous |
| 65 | +``` |
| 66 | + |
| 67 | +These patterns behave consistently across tmux versions and quoting contexts. |
0 commit comments