Formats in tmux¶
1. b:
and d:
(Basename and Dirname)¶
- Purpose: Extracts the basename (filename) and dirname (directory path) from a file path.
- Examples:
- Basename
(b:)
:- Given:
#{b:/usr/local/bin/tmux}
- Result:
tmux
(extracts just the filename).
- Given:
- Dirname
(d:)
:- Given:
#{d:/usr/local/bin/tmux}
- Result:
/usr/local/bin
(extracts the directory path).
- Given:
- Basename
2. q:
(Escape Special Characters)¶
- Purpose: Escapes shell special characters; q:h escapes hash characters.
- Examples:
- Escape Special Characters
(q:)
:- Given:
#{q:This
# is special} - Result: Escapes the # to be interpreted literally.
- Given:
- Escape Hash
(q:h)
:- Given:
#{q:h#}
- Result:
##
(makes # become ##).
- Given:
- Escape Special Characters
3. E:
(Double Expansion)¶
- Purpose: Expands the format twice, useful for nested formats.
- Example:
- Given:
#{E:status-left}
- Result: Expands the content of the
status-left
option rather than the option itself.
- Given:
4. T:
(Time Expansion)¶
- Purpose: Similar to
E:
, but also expandsstrftime
time specifiers. - Example:
- Given:
#{T:%Y-%m-%d %H:%M:%S}
- Result: Shows the current date and time.
- Given:
5. S:
, W:
, P:
(Looping Formats)¶
- Purpose: Loops over sessions, windows, or panes and applies the format to each.
- Examples:
- Windows Looping
(W:)
:- Given:
#{W:#{window_index} ,#{window_active}}
- Result: Lists window indices, with a special format for the active window.
- Given:
- Windows Looping
6. N:
(Existence Check)¶
- Purpose: Checks if a named window or session exists.
- Example:
- Given:
#{N/w:foo}
- Result: Replaced with
1
if a window namedfoo
exists, otherwise0
.
- Given:
7. s/foo/bar/:
(Substitution)¶
- Purpose: Substitutes
foo
withbar
in the string. - Examples:
- Basic Substitution:
- Given:
#{s/foo/bar/:foobar}
- Result:
barbar
(replacesfoo
withbar
).
- Given:
- Regex and Case-Insensitive:
- Given:
#{s/a(.)/\1x/i:abABab}
- Result:
bxBxbx
(applies regex substitution).
- Given:
- Basic Substitution:
8. #()
(Shell Command Output)¶
- Purpose: Inserts the output of a shell command.
- Example:
- Given:
#(uptime)
- Result: Inserts the system's uptime.
- Given:
9. l:
(Literal Interpretation)¶
- Purpose: Interprets a string literally without expansion.
- Example:
- Given:
#{l:#{?pane_in_mode,yes,no}}
- Result:
#{?pane_in_mode,yes,no}
(treated as a literal string).
- Given:
Use Cases and Additional Examples¶
- Dynamic Status Line
- Using
#{W:...}
to create a custom status line that shows different formats for active and inactive windows.
- Using
- Custom Information Display
- Using
#(uptime)
to display system uptime in the status bar.
- Using
- Conditional Formatting
- Using
#{?pane_in_mode,yes,no}
with#{l:...}
to display whether the current pane is in a specific mode.
- Using
- File Path Manipulation
- Displaying just the directory or filename of a path in a pane title with
#{b:...}
and#{d:...}
.
- Displaying just the directory or filename of a path in a pane title with
- Data Transformation
- Using
#{s/foo/bar/:}
to dynamically change displayed text based on certain conditions or input.
- Using
Each of these formatting options allows for a high degree of customization in how information is displayed and managed within tmux, providing a powerful toolkit for enhancing your terminal experience.