Skip to content

Instantly share code, notes, and snippets.

@igor-ramazanov
Created October 27, 2023 10:26
Show Gist options
  • Save igor-ramazanov/b42b6dbcd416276d0e0ea38a0f388f14 to your computer and use it in GitHub Desktop.
Save igor-ramazanov/b42b6dbcd416276d0e0ea38a0f388f14 to your computer and use it in GitHub Desktop.
Tmux FORMATs cheatsheet

Tmux cheatsheet

Conditionals

? - Conditionals, if a variable exists and non-zero, then the first is chosen, otherwise second.
Example: #{?session_attached,attached,not attached}.

Comparisons

==:, !=:, <:, >:, <=:, >=: - String comparisons.
Example #{==:#{host},nixos} will be either 1 or 0.

Booleans

||:, &&: - Logical ANDs and ORs.
Example #{||:#{pane_in_mode},#{alternate_on}}.

Matching strings

m: - fnmatch(3) comparison, example #{m:*foo*,#{host}}.
m/r: - Regular expressions matching, example #{m/r:^foo.*$,#{pane_current_path}}.
m/i: - Ignore the case.
m/ri: - Combine Regular expressions and ignoring the case.
s/foo/bar/i: - Substitute foo with bar ignoring the case, similar to sed. It is possible to use a different separator character, e.g. #{s|/home/igor|~:pane_current_path}.

Pane content

C: - Search in for the pane content using fnmatch(3), return line number if found, 0 otherwise.
C/r: - The same as the previous, but using Regular expressions, example #{C/r:^Start}.
C/i: - Ignore the case.
C/ri: - Combine Regular expressions and ignoring the case.\

Numerical operations

e|+|:, e|-|:, e|*|:, e|/|:, e|m|: (Modulus operation), e|==|:, e|!=|:, e|<|:, e|>|:, e|<=|:, e|=>|: - Numerical operations, integers only.
Example #{e|+|:5,3}.

e|+|f: - Floating numbers, example #{e|*|,2.5,2}.
e|+|f|4: - Specify decimal output size for a result.

Padding and trimming

=5: - Limit a string to 5 characters starting from the beginning.
=-5: - Limit a string to 5 characters taking the last 5 characters.
=/5/...: - Limit a string to 5 characters, and if trimmed then append ..., for example #{=/5/...:pane_current_path} turns to /home....
=/-5/...: - Limit a string to 5 characters from the tail, and if trimmed then prepend ..., for example #{=/-5/...:pane_current_path} turns to ...files.

Filenames

b: - Extract a basename, for example #{b:pane_current_path} turns to dotfiles.
d: - Extract a dirname, for example #{d:pane_current_path} turns to /home/igor/personal.

Looping over sessions, windows and panes

S: - Loop over sessions, append strings to each other.

W: - Loop over windows, append strings to each other.
If one argument, then loop over all: #{W: #{pane_id} }.
If two arguments, then loop separately over active and inactive: #{W: window-#W-active , window-#W-inactive }.

P: - Same as for W but for panes.
If one argument, then loop over all: #{P:#{pane_id}.
If two arguments, then loop separately over active and inactive: #{P: pane-id-#D-active , pane-id-#D-inactive }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment