tmux_styler.ContextVars

tmux context variables.

  1"""
  2tmux context variables.
  3"""
  4from enum import Enum
  5import subprocess
  6from typing import List
  7
  8
  9# TODO: Some context variables could be given better names and descriptions,
 10#       much of this was generated by ChatGPT from copy pasting directly tmux man page.
 11#       https://man7.org/linux/man-pages/man1/tmux.1.html#FORMATS
 12class ContextVar(Enum):
 13    """
 14    tmux context variables.
 15
 16    Methods:
 17    --------
 18    current_value() -> str
 19        Returns the current value of the context variable from tmux.
 20    """
 21
 22    ACTIVE_WINDOW_INDEX = "active_window_index"
 23    """
 24    Index of active window in session
 25    """
 26
 27    ALTERNATE_ON = "alternate_on"
 28    """
 29    1 if pane is in alternate screen
 30    """
 31
 32    ALTERNATE_SAVED_X = "alternate_saved_x"
 33    """
 34    Saved cursor X in alternate screen
 35    """
 36
 37    ALTERNATE_SAVED_Y = "alternate_saved_y"
 38    """
 39    Saved cursor Y in alternate screen
 40    """
 41
 42    BUFFER_CREATED = "buffer_created"
 43    """
 44    Time buffer created
 45    """
 46
 47    BUFFER_NAME = "buffer_name"
 48    """
 49    Name of buffer
 50    """
 51
 52    BUFFER_SAMPLE = "buffer_sample"
 53    """
 54    Sample of start of buffer
 55    """
 56
 57    BUFFER_SIZE = "buffer_size"
 58    """
 59    Size of the specified buffer in bytes
 60    """
 61
 62    CLIENT_ACTIVITY = "client_activity"
 63    """
 64    Time client last had activity
 65    """
 66
 67    CLIENT_CELL_HEIGHT = "client_cell_height"
 68    """
 69    Height of each client cell in pixels
 70    """
 71
 72    CLIENT_CELL_WIDTH = "client_cell_width"
 73    """
 74    Width of each client cell in pixels
 75    """
 76
 77    CLIENT_CONTROL_MODE = "client_control_mode"
 78    """
 79    1 if client is in control mode
 80    """
 81
 82    CLIENT_CREATED = "client_created"
 83    """
 84    Time client created
 85    """
 86
 87    CLIENT_DISCARDED = "client_discarded"
 88    """
 89    Bytes discarded when client behind
 90    """
 91
 92    CLIENT_FLAGS = "client_flags"
 93    """
 94    List of client flags
 95    """
 96
 97    CLIENT_HEIGHT = "client_height"
 98    """
 99    Height of client
100    """
101
102    CLIENT_KEY_TABLE = "client_key_table"
103    """
104    Current key table
105    """
106
107    CLIENT_LAST_SESSION = "client_last_session"
108    """
109    Name of the client's last session
110    """
111
112    CLIENT_NAME = "client_name"
113    """
114    Name of client
115    """
116
117    CLIENT_PID = "client_pid"
118    """
119    PID of client process
120    """
121
122    CLIENT_PREFIX = "client_prefix"
123    """
124    1 if prefix key has been pressed
125    """
126
127    CLIENT_READONLY = "client_readonly"
128    """
129    1 if client is read-only
130    """
131
132    CLIENT_SESSION = "client_session"
133    """
134    Name of the client's session
135    """
136
137    CLIENT_TERMFEATURES = "client_termfeatures"
138    """
139    Terminal features of client, if any
140    """
141
142    CLIENT_TERMNAME = "client_termname"
143    """
144    Terminal name of client
145    """
146
147    CLIENT_TERMTYPE = "client_termtype"
148    """
149    Terminal type of client, if available
150    """
151
152    CLIENT_TTY = "client_tty"
153    """
154    Pseudo terminal of client
155    """
156
157    CLIENT_UID = "client_uid"
158    """
159    UID of client process
160    """
161
162    CLIENT_USER = "client_user"
163    """
164    User of client process
165    """
166
167    CLIENT_UTF8 = "client_utf8"
168    """
169    1 if client supports UTF-8
170    """
171
172    CLIENT_WIDTH = "client_width"
173    """
174    Width of client
175    """
176
177    CLIENT_WRITTEN = "client_written"
178    """
179    Bytes written to client
180    """
181
182    COMMAND = "command"
183    """
184    Name of command in use, if any
185    """
186
187    COMMAND_LIST_ALIAS = "command_list_alias"
188    """
189    Command alias if listing commands
190    """
191
192    COMMAND_LIST_NAME = "command_list_name"
193    """
194    Command name if listing commands
195    """
196
197    COMMAND_LIST_USAGE = "command_list_usage"
198    """
199    Command usage if listing commands
200    """
201
202    CONFIG_FILES = "config_files"
203    """
204    List of configuration files loaded
205    """
206
207    COPY_CURSOR_LINE = "copy_cursor_line"
208    """
209    Line the cursor is on in copy mode
210    """
211
212    COPY_CURSOR_WORD = "copy_cursor_word"
213    """
214    Word under cursor in copy mode
215    """
216
217    COPY_CURSOR_X = "copy_cursor_x"
218    """
219    Cursor X position in copy mode
220    """
221
222    COPY_CURSOR_Y = "copy_cursor_y"
223    """
224    Cursor Y position in copy mode
225    """
226
227    CURRENT_FILE = "current_file"
228    """
229    Current configuration file
230    """
231
232    CURSOR_CHARACTER = "cursor_character"
233    """
234    Character at cursor in pane
235    """
236
237    CURSOR_FLAG = "cursor_flag"
238    """
239    Pane cursor flag
240    """
241
242    CURSOR_X = "cursor_x"
243    """
244    Cursor X position in pane
245    """
246
247    CURSOR_Y = "cursor_y"
248    """
249    Cursor Y position in pane
250    """
251
252    HISTORY_BYTES = "history_bytes"
253    """
254    Number of bytes in window history
255    """
256
257    HISTORY_LIMIT = "history_limit"
258    """
259    Maximum window history lines
260    """
261
262    HISTORY_SIZE = "history_size"
263    """
264    Size of history in lines
265    """
266
267    HOOK = "hook"
268    """
269    Name of running hook, if any
270    """
271
272    HOOK_CLIENT = "hook_client"
273    """
274    Name of client where hook was run, if any
275    """
276
277    HOOK_PANE = "hook_pane"
278    """
279    ID of pane where hook was run, if any
280    """
281
282    HOOK_SESSION = "hook_session"
283    """
284    ID of session where hook was run, if any
285    """
286
287    HOOK_SESSION_NAME = "hook_session_name"
288    """
289    Name of session where hook was run, if any
290    """
291
292    HOOK_WINDOW = "hook_window"
293    """
294    ID of window where hook was run, if any
295    """
296
297    HOOK_WINDOW_NAME = "hook_window_name"
298    """
299    Name of window where hook was run, if any
300    """
301
302    HOST = "host"
303    """
304    Hostname of local host
305    """
306
307    HOST_SHORT = "host_short"
308    """
309    Hostname of local host (no domain name)
310    """
311
312    INSERT_FLAG = "insert_flag"
313    """
314    Pane insert flag
315    """
316
317    KEYPAD_CURSOR_FLAG = "keypad_cursor_flag"
318    """
319    Pane keypad cursor flag
320    """
321
322    KEYPAD_FLAG = "keypad_flag"
323    """
324    Pane keypad flag
325    """
326
327    LAST_WINDOW_INDEX = "last_window_index"
328    """
329    Index of last window in session
330    """
331
332    LINE = "line"
333    """
334    Line number in the list
335    """
336
337    MOUSE_ALL_FLAG = "mouse_all_flag"
338    """
339    Pane mouse all flag
340    """
341
342    MOUSE_ANY_FLAG = "mouse_any_flag"
343    """
344    Pane mouse any flag
345    """
346
347    MOUSE_BUTTON_FLAG = "mouse_button_flag"
348    """
349    Pane mouse button flag
350    """
351
352    MOUSE_HYPERLINK = "mouse_hyperlink"
353    """
354    Hyperlink under mouse, if any
355    """
356
357    MOUSE_LINE = "mouse_line"
358    """
359    Line under mouse, if any
360    """
361
362    MOUSE_SGR_FLAG = "mouse_sgr_flag"
363    """
364    Pane mouse SGR flag
365    """
366
367    MOUSE_STANDARD_FLAG = "mouse_standard_flag"
368    """
369    Pane mouse standard flag
370    """
371
372    MOUSE_UTF8_FLAG = "mouse_utf8_flag"
373    """
374    Pane mouse UTF-8 flag
375    """
376
377    MOUSE_WORD = "mouse_word"
378    """
379    Word under mouse, if any
380    """
381
382    MOUSE_X = "mouse_x"
383    """
384    Mouse X position, if any
385    """
386
387    MOUSE_Y = "mouse_y"
388    """
389    Mouse Y position, if any
390    """
391
392    NEXT_SESSION_ID = "next_session_id"
393    """
394    Unique session ID for next new session
395    """
396
397    ORIGIN_FLAG = "origin_flag"
398    """
399    Pane origin flag
400    """
401
402    PANE_ACTIVE = "pane_active"
403    """
404    1 if active pane
405    """
406
407    PANE_AT_BOTTOM = "pane_at_bottom"
408    """
409    1 if pane is at the bottom of window
410    """
411
412    PANE_AT_LEFT = "pane_at_left"
413    """
414    1 if pane is at the left of window
415    """
416
417    PANE_AT_RIGHT = "pane_at_right"
418    """
419    1 if pane is at the right of window
420    """
421
422    PANE_AT_TOP = "pane_at_top"
423    """
424    1 if pane is at the top of window
425    """
426
427    PANE_BG = "pane_bg"
428    """
429    Pane background colour
430    """
431
432    PANE_BOTTOM = "pane_bottom"
433    """
434    Bottom of pane
435    """
436
437    PANE_CURRENT_COMMAND = "pane_current_command"
438    """
439    Current command if available
440    """
441
442    PANE_CURRENT_PATH = "pane_current_path"
443    """
444    Current path if available
445    """
446
447    PANE_DEAD = "pane_dead"
448    """
449    1 if pane is dead
450    """
451
452    PANE_DEAD_SIGNAL = "pane_dead_signal"
453    """
454    Exit signal of process in dead pane
455    """
456
457    PANE_DEAD_STATUS = "pane_dead_status"
458    """
459    Exit status of process in dead pane
460    """
461
462    PANE_DEAD_TIME = "pane_dead_time"
463    """
464    Exit time of process in dead pane
465    """
466
467    PANE_FG = "pane_fg"
468    """
469    Pane foreground colour
470    """
471
472    PANE_FORMAT = "pane_format"
473    """
474    1 if format is for a pane
475    """
476
477    PANE_HEIGHT = "pane_height"
478    """
479    Height of pane
480    """
481
482    PANE_ID = "pane_id"
483    """
484    Unique pane ID
485    """
486
487    PANE_IN_MODE = "pane_in_mode"
488    """
489    1 if pane is in a mode
490    """
491
492    PANE_INDEX = "pane_index"
493    """
494    Index of pane
495    """
496
497    PANE_INPUT_OFF = "pane_input_off"
498    """
499    1 if input to pane is disabled
500    """
501
502    PANE_LAST = "pane_last"
503    """
504    1 if last pane
505    """
506
507    PANE_LEFT = "pane_left"
508    """
509    Left of pane
510    """
511
512    PANE_MARKED = "pane_marked"
513    """
514    1 if this is the marked pane
515    """
516
517    PANE_MARKED_SET = "pane_marked_set"
518    """
519    1 if a marked pane is set
520    """
521
522    PANE_MODE = "pane_mode"
523    """
524    Name of pane mode, if any
525    """
526
527    PANE_PATH = "pane_path"
528    """
529    Path of pane (can be set by application)
530    """
531
532    PANE_PID = "pane_pid"
533    """
534    PID of first process in pane
535    """
536
537    PANE_PIPE = "pane_pipe"
538    """
539    1 if pane is being piped
540    """
541
542    PANE_RIGHT = "pane_right"
543    """
544    Right of pane
545    """
546
547    PANE_SEARCH_STRING = "pane_search_string"
548    """
549    Last search string in copy mode
550    """
551
552    PANE_START_COMMAND = "pane_start_command"
553    """
554    Command pane started with
555    """
556
557    PANE_START_PATH = "pane_start_path"
558    """
559    Path pane started with
560    """
561
562    PANE_SYNCHRONIZED = "pane_synchronized"
563    """
564    1 if pane is synchronized
565    """
566
567    PANE_TABS = "pane_tabs"
568    """
569    Pane tab positions
570    """
571
572    PANE_TITLE = "pane_title"
573    """
574    Title of pane (can be set by application)
575    """
576
577    PANE_TOP = "pane_top"
578    """
579    Top of pane
580    """
581
582    PANE_TTY = "pane_tty"
583    """
584    Pseudo terminal of pane
585    """
586
587    PANE_WIDTH = "pane_width"
588    """
589    Width of pane
590    """
591
592    PID = "pid"
593    """
594    Server PID
595    """
596
597    RECTANGLE_TOGGLE = "rectangle_toggle"
598    """
599    1 if rectangle selection is activated
600    """
601
602    SCROLL_POSITION = "scroll_position"
603    """
604    Scroll position in copy mode
605    """
606
607    SCROLL_REGION_LOWER = "scroll_region_lower"
608    """
609    Bottom of scroll region in pane
610    """
611
612    SCROLL_REGION_UPPER = "scroll_region_upper"
613    """
614    Top of scroll region in pane
615    """
616
617    SEARCH_MATCH = "search_match"
618    """
619    Search match if any
620    """
621
622    SEARCH_PRESENT = "search_present"
623    """
624    1 if search started in copy mode
625    """
626
627    SELECTION_ACTIVE = "selection_active"
628    """
629    1 if selection started and changes with the cursor in copy mode
630    """
631
632    SELECTION_END_X = "selection_end_x"
633    """
634    X position of the end of the selection
635    """
636
637    SELECTION_END_Y = "selection_end_y"
638    """
639    Y position of the end of the selection
640    """
641
642    SELECTION_PRESENT = "selection_present"
643    """
644    1 if selection started in copy mode
645    """
646
647    SELECTION_START_X = "selection_start_x"
648    """
649    X position of the start of the selection
650    """
651
652    SELECTION_START_Y = "selection_start_y"
653    """
654    Y position of the start of the selection
655    """
656
657    SESSION_ACTIVITY = "session_activity"
658    """
659    Time of session last activity
660    """
661
662    SESSION_ALERTS = "session_alerts"
663    """
664    List of window indexes with alerts
665    """
666
667    SESSION_ATTACHED = "session_attached"
668    """
669    Number of clients session is attached to
670    """
671
672    SESSION_ATTACHED_LIST = "session_attached_list"
673    """
674    List of clients session is attached to
675    """
676
677    SESSION_CREATED = "session_created"
678    """
679    Time session created
680    """
681
682    SESSION_FORMAT = "session_format"
683    """
684    1 if format is for a session
685    """
686
687    SESSION_GROUP = "session_group"
688    """
689    Name of session group
690    """
691
692    SESSION_GROUP_ATTACHED = "session_group_attached"
693    """
694    Number of clients sessions in group are attached to
695    """
696
697    SESSION_GROUP_ATTACHED_LIST = "session_group_attached_list"
698    """
699    List of clients sessions in group are attached to
700    """
701
702    SESSION_GROUP_LIST = "session_group_list"
703    """
704    List of sessions in group
705    """
706
707    SESSION_GROUP_MANY_ATTACHED = "session_group_many_attached"
708    """
709    1 if multiple clients attached to sessions in group
710    """
711
712    SESSION_GROUP_SIZE = "session_group_size"
713    """
714    Size of session group
715    """
716
717    SESSION_GROUPED = "session_grouped"
718    """
719    1 if session in a group
720    """
721
722    SESSION_ID = "session_id"
723    """
724    Unique session ID
725    """
726
727    SESSION_LAST_ATTACHED = "session_last_attached"
728    """
729    Time session last attached
730    """
731
732    SESSION_MANY_ATTACHED = "session_many_attached"
733    """
734    1 if multiple clients attached
735    """
736
737    SESSION_MARKED = "session_marked"
738    """
739    1 if this session contains the marked pane
740    """
741
742    SESSION_NAME = "session_name"
743    """
744    Name of session
745    """
746
747    SESSION_PATH = "session_path"
748    """
749    Working directory of session
750    """
751
752    SESSION_STACK = "session_stack"
753    """
754    Window indexes in most recent order
755    """
756
757    SESSION_WINDOWS = "session_windows"
758    """
759    Number of windows in session
760    """
761
762    SOCKET_PATH = "socket_path"
763    """
764    Server socket path
765    """
766
767    START_TIME = "start_time"
768    """
769    Server start time
770    """
771
772    UID = "uid"
773    """
774    Server UID
775    """
776
777    USER = "user"
778    """
779    Server user
780    """
781
782    VERSION = "version"
783    """
784    Server version
785    """
786
787    WINDOW_ACTIVE = "window_active"
788    """
789    1 if window active
790    """
791
792    WINDOW_ACTIVE_CLIENTS = "window_active_clients"
793    """
794    Number of clients viewing this window
795    """
796
797    WINDOW_ACTIVE_CLIENTS_LIST = "window_active_clients_list"
798    """
799    List of clients viewing this window
800    """
801
802    WINDOW_ACTIVE_SESSIONS = "window_active_sessions"
803    """
804    Number of sessions on which this window is active
805    """
806
807    WINDOW_ACTIVE_SESSIONS_LIST = "window_active_sessions_list"
808    """
809    List of sessions on which this window is active
810    """
811
812    WINDOW_ACTIVITY = "window_activity"
813    """
814    Time of window last activity
815    """
816
817    WINDOW_ACTIVITY_FLAG = "window_activity_flag"
818    """
819    1 if window has activity
820    """
821
822    WINDOW_BELL_FLAG = "window_bell_flag"
823    """
824    1 if window has bell
825    """
826
827    WINDOW_BIGGER = "window_bigger"
828    """
829    1 if window is larger than client
830    """
831
832    WINDOW_CELL_HEIGHT = "window_cell_height"
833    """
834    Height of each cell in pixels
835    """
836
837    WINDOW_CELL_WIDTH = "window_cell_width"
838    """
839    Width of each cell in pixels
840    """
841
842    WINDOW_END_FLAG = "window_end_flag"
843    """
844    1 if window has the highest index
845    """
846
847    WINDOW_FLAGS = "window_flags"
848    """
849    Window flags with # escaped as ##
850    """
851
852    WINDOW_FORMAT = "window_format"
853    """
854    1 if format is for a window
855    """
856
857    WINDOW_HEIGHT = "window_height"
858    """
859    Height of window
860    """
861
862    WINDOW_ID = "window_id"
863    """
864    Unique window ID
865    """
866
867    WINDOW_INDEX = "window_index"
868    """
869    Index of window
870    """
871
872    WINDOW_LAST_FLAG = "window_last_flag"
873    """
874    1 if window is the last used
875    """
876
877    WINDOW_LAYOUT = "window_layout"
878    """
879    Window layout description, ignoring zoomed window panes
880    """
881
882    WINDOW_LINKED = "window_linked"
883    """
884    1 if window is linked across sessions
885    """
886
887    WINDOW_LINKED_SESSIONS = "window_linked_sessions"
888    """
889    Number of sessions this window is linked to
890    """
891
892    WINDOW_LINKED_SESSIONS_LIST = "window_linked_sessions_list"
893    """
894    List of sessions this window is linked to
895    """
896
897    WINDOW_MARKED_FLAG = "window_marked_flag"
898    """
899    1 if window contains the marked pane
900    """
901
902    WINDOW_NAME = "window_name"
903    """
904    Name of window
905    """
906
907    WINDOW_OFFSET_X = "window_offset_x"
908    """
909    X offset into window if larger than client
910    """
911
912    WINDOW_OFFSET_Y = "window_offset_y"
913    """
914    Y offset into window if larger than client
915    """
916
917    WINDOW_PANES = "window_panes"
918    """
919    Number of panes in window
920    """
921
922    WINDOW_RAW_FLAGS = "window_raw_flags"
923    """
924    Window flags with nothing escaped
925    """
926
927    WINDOW_SILENCE_FLAG = "window_silence_flag"
928    """
929    1 if window has silence alert
930    """
931
932    WINDOW_STACK_INDEX = "window_stack_index"
933    """
934    Index in session most recent stack
935    """
936
937    WINDOW_START_FLAG = "window_start_flag"
938    """
939    1 if window has the lowest index
940    """
941
942    WINDOW_VISIBLE_LAYOUT = "window_visible_layout"
943    """
944    Window layout description, respecting zoomed window panes
945    """
946
947    WINDOW_WIDTH = "window_width"
948    """
949    Width of window
950    """
951
952    WINDOW_ZOOMED_FLAG = "window_zoomed_flag"
953    """
954    1 if window is zoomed
955    """
956
957    WRAP_FLAG = "wrap_flag"
958    """
959    Pane wrap flag
960    """
961
962    def __str__(self) -> str:
963        """
964        Returns the format string representation of context variables for use with tmux.
965        """
966        if self == self.PANE_CURRENT_COMMAND:
967            return "#(tmux-styler -ppid #{pane_pid})"
968        else:
969            return "#{{{}}}".format(self.value)
970
971    def current_value(self) -> str:
972        """
973        Returns the current value of the context variable.
974        """
975        # run shell command to get current value
976        return subprocess.run(["tmux", "display-message", "-p", f"'{str(self)}'"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
977
978
979def current_values(vars: List[ContextVar]) -> List[str]:
980    """
981    Returns the current values of the context variables as a list.
982    More efficient than calling current_value on each variable.
983    """
984    # call string on each variable
985    command = ["tmux", "display-message", "-p",
986               "\n".join([str(var) for var in vars])]
987    proc = subprocess.run(command, stdout=subprocess.PIPE)
988    # split the output and ruturn
989    return proc.stdout.decode("utf-8").strip().split("\n")
class ContextVar(enum.Enum):
 13class ContextVar(Enum):
 14    """
 15    tmux context variables.
 16
 17    Methods:
 18    --------
 19    current_value() -> str
 20        Returns the current value of the context variable from tmux.
 21    """
 22
 23    ACTIVE_WINDOW_INDEX = "active_window_index"
 24    """
 25    Index of active window in session
 26    """
 27
 28    ALTERNATE_ON = "alternate_on"
 29    """
 30    1 if pane is in alternate screen
 31    """
 32
 33    ALTERNATE_SAVED_X = "alternate_saved_x"
 34    """
 35    Saved cursor X in alternate screen
 36    """
 37
 38    ALTERNATE_SAVED_Y = "alternate_saved_y"
 39    """
 40    Saved cursor Y in alternate screen
 41    """
 42
 43    BUFFER_CREATED = "buffer_created"
 44    """
 45    Time buffer created
 46    """
 47
 48    BUFFER_NAME = "buffer_name"
 49    """
 50    Name of buffer
 51    """
 52
 53    BUFFER_SAMPLE = "buffer_sample"
 54    """
 55    Sample of start of buffer
 56    """
 57
 58    BUFFER_SIZE = "buffer_size"
 59    """
 60    Size of the specified buffer in bytes
 61    """
 62
 63    CLIENT_ACTIVITY = "client_activity"
 64    """
 65    Time client last had activity
 66    """
 67
 68    CLIENT_CELL_HEIGHT = "client_cell_height"
 69    """
 70    Height of each client cell in pixels
 71    """
 72
 73    CLIENT_CELL_WIDTH = "client_cell_width"
 74    """
 75    Width of each client cell in pixels
 76    """
 77
 78    CLIENT_CONTROL_MODE = "client_control_mode"
 79    """
 80    1 if client is in control mode
 81    """
 82
 83    CLIENT_CREATED = "client_created"
 84    """
 85    Time client created
 86    """
 87
 88    CLIENT_DISCARDED = "client_discarded"
 89    """
 90    Bytes discarded when client behind
 91    """
 92
 93    CLIENT_FLAGS = "client_flags"
 94    """
 95    List of client flags
 96    """
 97
 98    CLIENT_HEIGHT = "client_height"
 99    """
100    Height of client
101    """
102
103    CLIENT_KEY_TABLE = "client_key_table"
104    """
105    Current key table
106    """
107
108    CLIENT_LAST_SESSION = "client_last_session"
109    """
110    Name of the client's last session
111    """
112
113    CLIENT_NAME = "client_name"
114    """
115    Name of client
116    """
117
118    CLIENT_PID = "client_pid"
119    """
120    PID of client process
121    """
122
123    CLIENT_PREFIX = "client_prefix"
124    """
125    1 if prefix key has been pressed
126    """
127
128    CLIENT_READONLY = "client_readonly"
129    """
130    1 if client is read-only
131    """
132
133    CLIENT_SESSION = "client_session"
134    """
135    Name of the client's session
136    """
137
138    CLIENT_TERMFEATURES = "client_termfeatures"
139    """
140    Terminal features of client, if any
141    """
142
143    CLIENT_TERMNAME = "client_termname"
144    """
145    Terminal name of client
146    """
147
148    CLIENT_TERMTYPE = "client_termtype"
149    """
150    Terminal type of client, if available
151    """
152
153    CLIENT_TTY = "client_tty"
154    """
155    Pseudo terminal of client
156    """
157
158    CLIENT_UID = "client_uid"
159    """
160    UID of client process
161    """
162
163    CLIENT_USER = "client_user"
164    """
165    User of client process
166    """
167
168    CLIENT_UTF8 = "client_utf8"
169    """
170    1 if client supports UTF-8
171    """
172
173    CLIENT_WIDTH = "client_width"
174    """
175    Width of client
176    """
177
178    CLIENT_WRITTEN = "client_written"
179    """
180    Bytes written to client
181    """
182
183    COMMAND = "command"
184    """
185    Name of command in use, if any
186    """
187
188    COMMAND_LIST_ALIAS = "command_list_alias"
189    """
190    Command alias if listing commands
191    """
192
193    COMMAND_LIST_NAME = "command_list_name"
194    """
195    Command name if listing commands
196    """
197
198    COMMAND_LIST_USAGE = "command_list_usage"
199    """
200    Command usage if listing commands
201    """
202
203    CONFIG_FILES = "config_files"
204    """
205    List of configuration files loaded
206    """
207
208    COPY_CURSOR_LINE = "copy_cursor_line"
209    """
210    Line the cursor is on in copy mode
211    """
212
213    COPY_CURSOR_WORD = "copy_cursor_word"
214    """
215    Word under cursor in copy mode
216    """
217
218    COPY_CURSOR_X = "copy_cursor_x"
219    """
220    Cursor X position in copy mode
221    """
222
223    COPY_CURSOR_Y = "copy_cursor_y"
224    """
225    Cursor Y position in copy mode
226    """
227
228    CURRENT_FILE = "current_file"
229    """
230    Current configuration file
231    """
232
233    CURSOR_CHARACTER = "cursor_character"
234    """
235    Character at cursor in pane
236    """
237
238    CURSOR_FLAG = "cursor_flag"
239    """
240    Pane cursor flag
241    """
242
243    CURSOR_X = "cursor_x"
244    """
245    Cursor X position in pane
246    """
247
248    CURSOR_Y = "cursor_y"
249    """
250    Cursor Y position in pane
251    """
252
253    HISTORY_BYTES = "history_bytes"
254    """
255    Number of bytes in window history
256    """
257
258    HISTORY_LIMIT = "history_limit"
259    """
260    Maximum window history lines
261    """
262
263    HISTORY_SIZE = "history_size"
264    """
265    Size of history in lines
266    """
267
268    HOOK = "hook"
269    """
270    Name of running hook, if any
271    """
272
273    HOOK_CLIENT = "hook_client"
274    """
275    Name of client where hook was run, if any
276    """
277
278    HOOK_PANE = "hook_pane"
279    """
280    ID of pane where hook was run, if any
281    """
282
283    HOOK_SESSION = "hook_session"
284    """
285    ID of session where hook was run, if any
286    """
287
288    HOOK_SESSION_NAME = "hook_session_name"
289    """
290    Name of session where hook was run, if any
291    """
292
293    HOOK_WINDOW = "hook_window"
294    """
295    ID of window where hook was run, if any
296    """
297
298    HOOK_WINDOW_NAME = "hook_window_name"
299    """
300    Name of window where hook was run, if any
301    """
302
303    HOST = "host"
304    """
305    Hostname of local host
306    """
307
308    HOST_SHORT = "host_short"
309    """
310    Hostname of local host (no domain name)
311    """
312
313    INSERT_FLAG = "insert_flag"
314    """
315    Pane insert flag
316    """
317
318    KEYPAD_CURSOR_FLAG = "keypad_cursor_flag"
319    """
320    Pane keypad cursor flag
321    """
322
323    KEYPAD_FLAG = "keypad_flag"
324    """
325    Pane keypad flag
326    """
327
328    LAST_WINDOW_INDEX = "last_window_index"
329    """
330    Index of last window in session
331    """
332
333    LINE = "line"
334    """
335    Line number in the list
336    """
337
338    MOUSE_ALL_FLAG = "mouse_all_flag"
339    """
340    Pane mouse all flag
341    """
342
343    MOUSE_ANY_FLAG = "mouse_any_flag"
344    """
345    Pane mouse any flag
346    """
347
348    MOUSE_BUTTON_FLAG = "mouse_button_flag"
349    """
350    Pane mouse button flag
351    """
352
353    MOUSE_HYPERLINK = "mouse_hyperlink"
354    """
355    Hyperlink under mouse, if any
356    """
357
358    MOUSE_LINE = "mouse_line"
359    """
360    Line under mouse, if any
361    """
362
363    MOUSE_SGR_FLAG = "mouse_sgr_flag"
364    """
365    Pane mouse SGR flag
366    """
367
368    MOUSE_STANDARD_FLAG = "mouse_standard_flag"
369    """
370    Pane mouse standard flag
371    """
372
373    MOUSE_UTF8_FLAG = "mouse_utf8_flag"
374    """
375    Pane mouse UTF-8 flag
376    """
377
378    MOUSE_WORD = "mouse_word"
379    """
380    Word under mouse, if any
381    """
382
383    MOUSE_X = "mouse_x"
384    """
385    Mouse X position, if any
386    """
387
388    MOUSE_Y = "mouse_y"
389    """
390    Mouse Y position, if any
391    """
392
393    NEXT_SESSION_ID = "next_session_id"
394    """
395    Unique session ID for next new session
396    """
397
398    ORIGIN_FLAG = "origin_flag"
399    """
400    Pane origin flag
401    """
402
403    PANE_ACTIVE = "pane_active"
404    """
405    1 if active pane
406    """
407
408    PANE_AT_BOTTOM = "pane_at_bottom"
409    """
410    1 if pane is at the bottom of window
411    """
412
413    PANE_AT_LEFT = "pane_at_left"
414    """
415    1 if pane is at the left of window
416    """
417
418    PANE_AT_RIGHT = "pane_at_right"
419    """
420    1 if pane is at the right of window
421    """
422
423    PANE_AT_TOP = "pane_at_top"
424    """
425    1 if pane is at the top of window
426    """
427
428    PANE_BG = "pane_bg"
429    """
430    Pane background colour
431    """
432
433    PANE_BOTTOM = "pane_bottom"
434    """
435    Bottom of pane
436    """
437
438    PANE_CURRENT_COMMAND = "pane_current_command"
439    """
440    Current command if available
441    """
442
443    PANE_CURRENT_PATH = "pane_current_path"
444    """
445    Current path if available
446    """
447
448    PANE_DEAD = "pane_dead"
449    """
450    1 if pane is dead
451    """
452
453    PANE_DEAD_SIGNAL = "pane_dead_signal"
454    """
455    Exit signal of process in dead pane
456    """
457
458    PANE_DEAD_STATUS = "pane_dead_status"
459    """
460    Exit status of process in dead pane
461    """
462
463    PANE_DEAD_TIME = "pane_dead_time"
464    """
465    Exit time of process in dead pane
466    """
467
468    PANE_FG = "pane_fg"
469    """
470    Pane foreground colour
471    """
472
473    PANE_FORMAT = "pane_format"
474    """
475    1 if format is for a pane
476    """
477
478    PANE_HEIGHT = "pane_height"
479    """
480    Height of pane
481    """
482
483    PANE_ID = "pane_id"
484    """
485    Unique pane ID
486    """
487
488    PANE_IN_MODE = "pane_in_mode"
489    """
490    1 if pane is in a mode
491    """
492
493    PANE_INDEX = "pane_index"
494    """
495    Index of pane
496    """
497
498    PANE_INPUT_OFF = "pane_input_off"
499    """
500    1 if input to pane is disabled
501    """
502
503    PANE_LAST = "pane_last"
504    """
505    1 if last pane
506    """
507
508    PANE_LEFT = "pane_left"
509    """
510    Left of pane
511    """
512
513    PANE_MARKED = "pane_marked"
514    """
515    1 if this is the marked pane
516    """
517
518    PANE_MARKED_SET = "pane_marked_set"
519    """
520    1 if a marked pane is set
521    """
522
523    PANE_MODE = "pane_mode"
524    """
525    Name of pane mode, if any
526    """
527
528    PANE_PATH = "pane_path"
529    """
530    Path of pane (can be set by application)
531    """
532
533    PANE_PID = "pane_pid"
534    """
535    PID of first process in pane
536    """
537
538    PANE_PIPE = "pane_pipe"
539    """
540    1 if pane is being piped
541    """
542
543    PANE_RIGHT = "pane_right"
544    """
545    Right of pane
546    """
547
548    PANE_SEARCH_STRING = "pane_search_string"
549    """
550    Last search string in copy mode
551    """
552
553    PANE_START_COMMAND = "pane_start_command"
554    """
555    Command pane started with
556    """
557
558    PANE_START_PATH = "pane_start_path"
559    """
560    Path pane started with
561    """
562
563    PANE_SYNCHRONIZED = "pane_synchronized"
564    """
565    1 if pane is synchronized
566    """
567
568    PANE_TABS = "pane_tabs"
569    """
570    Pane tab positions
571    """
572
573    PANE_TITLE = "pane_title"
574    """
575    Title of pane (can be set by application)
576    """
577
578    PANE_TOP = "pane_top"
579    """
580    Top of pane
581    """
582
583    PANE_TTY = "pane_tty"
584    """
585    Pseudo terminal of pane
586    """
587
588    PANE_WIDTH = "pane_width"
589    """
590    Width of pane
591    """
592
593    PID = "pid"
594    """
595    Server PID
596    """
597
598    RECTANGLE_TOGGLE = "rectangle_toggle"
599    """
600    1 if rectangle selection is activated
601    """
602
603    SCROLL_POSITION = "scroll_position"
604    """
605    Scroll position in copy mode
606    """
607
608    SCROLL_REGION_LOWER = "scroll_region_lower"
609    """
610    Bottom of scroll region in pane
611    """
612
613    SCROLL_REGION_UPPER = "scroll_region_upper"
614    """
615    Top of scroll region in pane
616    """
617
618    SEARCH_MATCH = "search_match"
619    """
620    Search match if any
621    """
622
623    SEARCH_PRESENT = "search_present"
624    """
625    1 if search started in copy mode
626    """
627
628    SELECTION_ACTIVE = "selection_active"
629    """
630    1 if selection started and changes with the cursor in copy mode
631    """
632
633    SELECTION_END_X = "selection_end_x"
634    """
635    X position of the end of the selection
636    """
637
638    SELECTION_END_Y = "selection_end_y"
639    """
640    Y position of the end of the selection
641    """
642
643    SELECTION_PRESENT = "selection_present"
644    """
645    1 if selection started in copy mode
646    """
647
648    SELECTION_START_X = "selection_start_x"
649    """
650    X position of the start of the selection
651    """
652
653    SELECTION_START_Y = "selection_start_y"
654    """
655    Y position of the start of the selection
656    """
657
658    SESSION_ACTIVITY = "session_activity"
659    """
660    Time of session last activity
661    """
662
663    SESSION_ALERTS = "session_alerts"
664    """
665    List of window indexes with alerts
666    """
667
668    SESSION_ATTACHED = "session_attached"
669    """
670    Number of clients session is attached to
671    """
672
673    SESSION_ATTACHED_LIST = "session_attached_list"
674    """
675    List of clients session is attached to
676    """
677
678    SESSION_CREATED = "session_created"
679    """
680    Time session created
681    """
682
683    SESSION_FORMAT = "session_format"
684    """
685    1 if format is for a session
686    """
687
688    SESSION_GROUP = "session_group"
689    """
690    Name of session group
691    """
692
693    SESSION_GROUP_ATTACHED = "session_group_attached"
694    """
695    Number of clients sessions in group are attached to
696    """
697
698    SESSION_GROUP_ATTACHED_LIST = "session_group_attached_list"
699    """
700    List of clients sessions in group are attached to
701    """
702
703    SESSION_GROUP_LIST = "session_group_list"
704    """
705    List of sessions in group
706    """
707
708    SESSION_GROUP_MANY_ATTACHED = "session_group_many_attached"
709    """
710    1 if multiple clients attached to sessions in group
711    """
712
713    SESSION_GROUP_SIZE = "session_group_size"
714    """
715    Size of session group
716    """
717
718    SESSION_GROUPED = "session_grouped"
719    """
720    1 if session in a group
721    """
722
723    SESSION_ID = "session_id"
724    """
725    Unique session ID
726    """
727
728    SESSION_LAST_ATTACHED = "session_last_attached"
729    """
730    Time session last attached
731    """
732
733    SESSION_MANY_ATTACHED = "session_many_attached"
734    """
735    1 if multiple clients attached
736    """
737
738    SESSION_MARKED = "session_marked"
739    """
740    1 if this session contains the marked pane
741    """
742
743    SESSION_NAME = "session_name"
744    """
745    Name of session
746    """
747
748    SESSION_PATH = "session_path"
749    """
750    Working directory of session
751    """
752
753    SESSION_STACK = "session_stack"
754    """
755    Window indexes in most recent order
756    """
757
758    SESSION_WINDOWS = "session_windows"
759    """
760    Number of windows in session
761    """
762
763    SOCKET_PATH = "socket_path"
764    """
765    Server socket path
766    """
767
768    START_TIME = "start_time"
769    """
770    Server start time
771    """
772
773    UID = "uid"
774    """
775    Server UID
776    """
777
778    USER = "user"
779    """
780    Server user
781    """
782
783    VERSION = "version"
784    """
785    Server version
786    """
787
788    WINDOW_ACTIVE = "window_active"
789    """
790    1 if window active
791    """
792
793    WINDOW_ACTIVE_CLIENTS = "window_active_clients"
794    """
795    Number of clients viewing this window
796    """
797
798    WINDOW_ACTIVE_CLIENTS_LIST = "window_active_clients_list"
799    """
800    List of clients viewing this window
801    """
802
803    WINDOW_ACTIVE_SESSIONS = "window_active_sessions"
804    """
805    Number of sessions on which this window is active
806    """
807
808    WINDOW_ACTIVE_SESSIONS_LIST = "window_active_sessions_list"
809    """
810    List of sessions on which this window is active
811    """
812
813    WINDOW_ACTIVITY = "window_activity"
814    """
815    Time of window last activity
816    """
817
818    WINDOW_ACTIVITY_FLAG = "window_activity_flag"
819    """
820    1 if window has activity
821    """
822
823    WINDOW_BELL_FLAG = "window_bell_flag"
824    """
825    1 if window has bell
826    """
827
828    WINDOW_BIGGER = "window_bigger"
829    """
830    1 if window is larger than client
831    """
832
833    WINDOW_CELL_HEIGHT = "window_cell_height"
834    """
835    Height of each cell in pixels
836    """
837
838    WINDOW_CELL_WIDTH = "window_cell_width"
839    """
840    Width of each cell in pixels
841    """
842
843    WINDOW_END_FLAG = "window_end_flag"
844    """
845    1 if window has the highest index
846    """
847
848    WINDOW_FLAGS = "window_flags"
849    """
850    Window flags with # escaped as ##
851    """
852
853    WINDOW_FORMAT = "window_format"
854    """
855    1 if format is for a window
856    """
857
858    WINDOW_HEIGHT = "window_height"
859    """
860    Height of window
861    """
862
863    WINDOW_ID = "window_id"
864    """
865    Unique window ID
866    """
867
868    WINDOW_INDEX = "window_index"
869    """
870    Index of window
871    """
872
873    WINDOW_LAST_FLAG = "window_last_flag"
874    """
875    1 if window is the last used
876    """
877
878    WINDOW_LAYOUT = "window_layout"
879    """
880    Window layout description, ignoring zoomed window panes
881    """
882
883    WINDOW_LINKED = "window_linked"
884    """
885    1 if window is linked across sessions
886    """
887
888    WINDOW_LINKED_SESSIONS = "window_linked_sessions"
889    """
890    Number of sessions this window is linked to
891    """
892
893    WINDOW_LINKED_SESSIONS_LIST = "window_linked_sessions_list"
894    """
895    List of sessions this window is linked to
896    """
897
898    WINDOW_MARKED_FLAG = "window_marked_flag"
899    """
900    1 if window contains the marked pane
901    """
902
903    WINDOW_NAME = "window_name"
904    """
905    Name of window
906    """
907
908    WINDOW_OFFSET_X = "window_offset_x"
909    """
910    X offset into window if larger than client
911    """
912
913    WINDOW_OFFSET_Y = "window_offset_y"
914    """
915    Y offset into window if larger than client
916    """
917
918    WINDOW_PANES = "window_panes"
919    """
920    Number of panes in window
921    """
922
923    WINDOW_RAW_FLAGS = "window_raw_flags"
924    """
925    Window flags with nothing escaped
926    """
927
928    WINDOW_SILENCE_FLAG = "window_silence_flag"
929    """
930    1 if window has silence alert
931    """
932
933    WINDOW_STACK_INDEX = "window_stack_index"
934    """
935    Index in session most recent stack
936    """
937
938    WINDOW_START_FLAG = "window_start_flag"
939    """
940    1 if window has the lowest index
941    """
942
943    WINDOW_VISIBLE_LAYOUT = "window_visible_layout"
944    """
945    Window layout description, respecting zoomed window panes
946    """
947
948    WINDOW_WIDTH = "window_width"
949    """
950    Width of window
951    """
952
953    WINDOW_ZOOMED_FLAG = "window_zoomed_flag"
954    """
955    1 if window is zoomed
956    """
957
958    WRAP_FLAG = "wrap_flag"
959    """
960    Pane wrap flag
961    """
962
963    def __str__(self) -> str:
964        """
965        Returns the format string representation of context variables for use with tmux.
966        """
967        if self == self.PANE_CURRENT_COMMAND:
968            return "#(tmux-styler -ppid #{pane_pid})"
969        else:
970            return "#{{{}}}".format(self.value)
971
972    def current_value(self) -> str:
973        """
974        Returns the current value of the context variable.
975        """
976        # run shell command to get current value
977        return subprocess.run(["tmux", "display-message", "-p", f"'{str(self)}'"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()

tmux context variables.

Methods:

current_value() -> str Returns the current value of the context variable from tmux.

ACTIVE_WINDOW_INDEX = <ContextVar.ACTIVE_WINDOW_INDEX: 'active_window_index'>

Index of active window in session

ALTERNATE_ON = <ContextVar.ALTERNATE_ON: 'alternate_on'>

1 if pane is in alternate screen

ALTERNATE_SAVED_X = <ContextVar.ALTERNATE_SAVED_X: 'alternate_saved_x'>

Saved cursor X in alternate screen

ALTERNATE_SAVED_Y = <ContextVar.ALTERNATE_SAVED_Y: 'alternate_saved_y'>

Saved cursor Y in alternate screen

BUFFER_CREATED = <ContextVar.BUFFER_CREATED: 'buffer_created'>

Time buffer created

BUFFER_NAME = <ContextVar.BUFFER_NAME: 'buffer_name'>

Name of buffer

BUFFER_SAMPLE = <ContextVar.BUFFER_SAMPLE: 'buffer_sample'>

Sample of start of buffer

BUFFER_SIZE = <ContextVar.BUFFER_SIZE: 'buffer_size'>

Size of the specified buffer in bytes

CLIENT_ACTIVITY = <ContextVar.CLIENT_ACTIVITY: 'client_activity'>

Time client last had activity

CLIENT_CELL_HEIGHT = <ContextVar.CLIENT_CELL_HEIGHT: 'client_cell_height'>

Height of each client cell in pixels

CLIENT_CELL_WIDTH = <ContextVar.CLIENT_CELL_WIDTH: 'client_cell_width'>

Width of each client cell in pixels

CLIENT_CONTROL_MODE = <ContextVar.CLIENT_CONTROL_MODE: 'client_control_mode'>

1 if client is in control mode

CLIENT_CREATED = <ContextVar.CLIENT_CREATED: 'client_created'>

Time client created

CLIENT_DISCARDED = <ContextVar.CLIENT_DISCARDED: 'client_discarded'>

Bytes discarded when client behind

CLIENT_FLAGS = <ContextVar.CLIENT_FLAGS: 'client_flags'>

List of client flags

CLIENT_HEIGHT = <ContextVar.CLIENT_HEIGHT: 'client_height'>

Height of client

CLIENT_KEY_TABLE = <ContextVar.CLIENT_KEY_TABLE: 'client_key_table'>

Current key table

CLIENT_LAST_SESSION = <ContextVar.CLIENT_LAST_SESSION: 'client_last_session'>

Name of the client's last session

CLIENT_NAME = <ContextVar.CLIENT_NAME: 'client_name'>

Name of client

CLIENT_PID = <ContextVar.CLIENT_PID: 'client_pid'>

PID of client process

CLIENT_PREFIX = <ContextVar.CLIENT_PREFIX: 'client_prefix'>

1 if prefix key has been pressed

CLIENT_READONLY = <ContextVar.CLIENT_READONLY: 'client_readonly'>

1 if client is read-only

CLIENT_SESSION = <ContextVar.CLIENT_SESSION: 'client_session'>

Name of the client's session

CLIENT_TERMFEATURES = <ContextVar.CLIENT_TERMFEATURES: 'client_termfeatures'>

Terminal features of client, if any

CLIENT_TERMNAME = <ContextVar.CLIENT_TERMNAME: 'client_termname'>

Terminal name of client

CLIENT_TERMTYPE = <ContextVar.CLIENT_TERMTYPE: 'client_termtype'>

Terminal type of client, if available

CLIENT_TTY = <ContextVar.CLIENT_TTY: 'client_tty'>

Pseudo terminal of client

CLIENT_UID = <ContextVar.CLIENT_UID: 'client_uid'>

UID of client process

CLIENT_USER = <ContextVar.CLIENT_USER: 'client_user'>

User of client process

CLIENT_UTF8 = <ContextVar.CLIENT_UTF8: 'client_utf8'>

1 if client supports UTF-8

CLIENT_WIDTH = <ContextVar.CLIENT_WIDTH: 'client_width'>

Width of client

CLIENT_WRITTEN = <ContextVar.CLIENT_WRITTEN: 'client_written'>

Bytes written to client

COMMAND = <ContextVar.COMMAND: 'command'>

Name of command in use, if any

COMMAND_LIST_ALIAS = <ContextVar.COMMAND_LIST_ALIAS: 'command_list_alias'>

Command alias if listing commands

COMMAND_LIST_NAME = <ContextVar.COMMAND_LIST_NAME: 'command_list_name'>

Command name if listing commands

COMMAND_LIST_USAGE = <ContextVar.COMMAND_LIST_USAGE: 'command_list_usage'>

Command usage if listing commands

CONFIG_FILES = <ContextVar.CONFIG_FILES: 'config_files'>

List of configuration files loaded

COPY_CURSOR_LINE = <ContextVar.COPY_CURSOR_LINE: 'copy_cursor_line'>

Line the cursor is on in copy mode

COPY_CURSOR_WORD = <ContextVar.COPY_CURSOR_WORD: 'copy_cursor_word'>

Word under cursor in copy mode

COPY_CURSOR_X = <ContextVar.COPY_CURSOR_X: 'copy_cursor_x'>

Cursor X position in copy mode

COPY_CURSOR_Y = <ContextVar.COPY_CURSOR_Y: 'copy_cursor_y'>

Cursor Y position in copy mode

CURRENT_FILE = <ContextVar.CURRENT_FILE: 'current_file'>

Current configuration file

CURSOR_CHARACTER = <ContextVar.CURSOR_CHARACTER: 'cursor_character'>

Character at cursor in pane

CURSOR_FLAG = <ContextVar.CURSOR_FLAG: 'cursor_flag'>

Pane cursor flag

CURSOR_X = <ContextVar.CURSOR_X: 'cursor_x'>

Cursor X position in pane

CURSOR_Y = <ContextVar.CURSOR_Y: 'cursor_y'>

Cursor Y position in pane

HISTORY_BYTES = <ContextVar.HISTORY_BYTES: 'history_bytes'>

Number of bytes in window history

HISTORY_LIMIT = <ContextVar.HISTORY_LIMIT: 'history_limit'>

Maximum window history lines

HISTORY_SIZE = <ContextVar.HISTORY_SIZE: 'history_size'>

Size of history in lines

HOOK = <ContextVar.HOOK: 'hook'>

Name of running hook, if any

HOOK_CLIENT = <ContextVar.HOOK_CLIENT: 'hook_client'>

Name of client where hook was run, if any

HOOK_PANE = <ContextVar.HOOK_PANE: 'hook_pane'>

ID of pane where hook was run, if any

HOOK_SESSION = <ContextVar.HOOK_SESSION: 'hook_session'>

ID of session where hook was run, if any

HOOK_SESSION_NAME = <ContextVar.HOOK_SESSION_NAME: 'hook_session_name'>

Name of session where hook was run, if any

HOOK_WINDOW = <ContextVar.HOOK_WINDOW: 'hook_window'>

ID of window where hook was run, if any

HOOK_WINDOW_NAME = <ContextVar.HOOK_WINDOW_NAME: 'hook_window_name'>

Name of window where hook was run, if any

HOST = <ContextVar.HOST: 'host'>

Hostname of local host

HOST_SHORT = <ContextVar.HOST_SHORT: 'host_short'>

Hostname of local host (no domain name)

INSERT_FLAG = <ContextVar.INSERT_FLAG: 'insert_flag'>

Pane insert flag

KEYPAD_CURSOR_FLAG = <ContextVar.KEYPAD_CURSOR_FLAG: 'keypad_cursor_flag'>

Pane keypad cursor flag

KEYPAD_FLAG = <ContextVar.KEYPAD_FLAG: 'keypad_flag'>

Pane keypad flag

LAST_WINDOW_INDEX = <ContextVar.LAST_WINDOW_INDEX: 'last_window_index'>

Index of last window in session

LINE = <ContextVar.LINE: 'line'>

Line number in the list

MOUSE_ALL_FLAG = <ContextVar.MOUSE_ALL_FLAG: 'mouse_all_flag'>

Pane mouse all flag

MOUSE_ANY_FLAG = <ContextVar.MOUSE_ANY_FLAG: 'mouse_any_flag'>

Pane mouse any flag

MOUSE_BUTTON_FLAG = <ContextVar.MOUSE_BUTTON_FLAG: 'mouse_button_flag'>

Pane mouse button flag

MOUSE_LINE = <ContextVar.MOUSE_LINE: 'mouse_line'>

Line under mouse, if any

MOUSE_SGR_FLAG = <ContextVar.MOUSE_SGR_FLAG: 'mouse_sgr_flag'>

Pane mouse SGR flag

MOUSE_STANDARD_FLAG = <ContextVar.MOUSE_STANDARD_FLAG: 'mouse_standard_flag'>

Pane mouse standard flag

MOUSE_UTF8_FLAG = <ContextVar.MOUSE_UTF8_FLAG: 'mouse_utf8_flag'>

Pane mouse UTF-8 flag

MOUSE_WORD = <ContextVar.MOUSE_WORD: 'mouse_word'>

Word under mouse, if any

MOUSE_X = <ContextVar.MOUSE_X: 'mouse_x'>

Mouse X position, if any

MOUSE_Y = <ContextVar.MOUSE_Y: 'mouse_y'>

Mouse Y position, if any

NEXT_SESSION_ID = <ContextVar.NEXT_SESSION_ID: 'next_session_id'>

Unique session ID for next new session

ORIGIN_FLAG = <ContextVar.ORIGIN_FLAG: 'origin_flag'>

Pane origin flag

PANE_ACTIVE = <ContextVar.PANE_ACTIVE: 'pane_active'>

1 if active pane

PANE_AT_BOTTOM = <ContextVar.PANE_AT_BOTTOM: 'pane_at_bottom'>

1 if pane is at the bottom of window

PANE_AT_LEFT = <ContextVar.PANE_AT_LEFT: 'pane_at_left'>

1 if pane is at the left of window

PANE_AT_RIGHT = <ContextVar.PANE_AT_RIGHT: 'pane_at_right'>

1 if pane is at the right of window

PANE_AT_TOP = <ContextVar.PANE_AT_TOP: 'pane_at_top'>

1 if pane is at the top of window

PANE_BG = <ContextVar.PANE_BG: 'pane_bg'>

Pane background colour

PANE_BOTTOM = <ContextVar.PANE_BOTTOM: 'pane_bottom'>

Bottom of pane

PANE_CURRENT_COMMAND = <ContextVar.PANE_CURRENT_COMMAND: 'pane_current_command'>

Current command if available

PANE_CURRENT_PATH = <ContextVar.PANE_CURRENT_PATH: 'pane_current_path'>

Current path if available

PANE_DEAD = <ContextVar.PANE_DEAD: 'pane_dead'>

1 if pane is dead

PANE_DEAD_SIGNAL = <ContextVar.PANE_DEAD_SIGNAL: 'pane_dead_signal'>

Exit signal of process in dead pane

PANE_DEAD_STATUS = <ContextVar.PANE_DEAD_STATUS: 'pane_dead_status'>

Exit status of process in dead pane

PANE_DEAD_TIME = <ContextVar.PANE_DEAD_TIME: 'pane_dead_time'>

Exit time of process in dead pane

PANE_FG = <ContextVar.PANE_FG: 'pane_fg'>

Pane foreground colour

PANE_FORMAT = <ContextVar.PANE_FORMAT: 'pane_format'>

1 if format is for a pane

PANE_HEIGHT = <ContextVar.PANE_HEIGHT: 'pane_height'>

Height of pane

PANE_ID = <ContextVar.PANE_ID: 'pane_id'>

Unique pane ID

PANE_IN_MODE = <ContextVar.PANE_IN_MODE: 'pane_in_mode'>

1 if pane is in a mode

PANE_INDEX = <ContextVar.PANE_INDEX: 'pane_index'>

Index of pane

PANE_INPUT_OFF = <ContextVar.PANE_INPUT_OFF: 'pane_input_off'>

1 if input to pane is disabled

PANE_LAST = <ContextVar.PANE_LAST: 'pane_last'>

1 if last pane

PANE_LEFT = <ContextVar.PANE_LEFT: 'pane_left'>

Left of pane

PANE_MARKED = <ContextVar.PANE_MARKED: 'pane_marked'>

1 if this is the marked pane

PANE_MARKED_SET = <ContextVar.PANE_MARKED_SET: 'pane_marked_set'>

1 if a marked pane is set

PANE_MODE = <ContextVar.PANE_MODE: 'pane_mode'>

Name of pane mode, if any

PANE_PATH = <ContextVar.PANE_PATH: 'pane_path'>

Path of pane (can be set by application)

PANE_PID = <ContextVar.PANE_PID: 'pane_pid'>

PID of first process in pane

PANE_PIPE = <ContextVar.PANE_PIPE: 'pane_pipe'>

1 if pane is being piped

PANE_RIGHT = <ContextVar.PANE_RIGHT: 'pane_right'>

Right of pane

PANE_SEARCH_STRING = <ContextVar.PANE_SEARCH_STRING: 'pane_search_string'>

Last search string in copy mode

PANE_START_COMMAND = <ContextVar.PANE_START_COMMAND: 'pane_start_command'>

Command pane started with

PANE_START_PATH = <ContextVar.PANE_START_PATH: 'pane_start_path'>

Path pane started with

PANE_SYNCHRONIZED = <ContextVar.PANE_SYNCHRONIZED: 'pane_synchronized'>

1 if pane is synchronized

PANE_TABS = <ContextVar.PANE_TABS: 'pane_tabs'>

Pane tab positions

PANE_TITLE = <ContextVar.PANE_TITLE: 'pane_title'>

Title of pane (can be set by application)

PANE_TOP = <ContextVar.PANE_TOP: 'pane_top'>

Top of pane

PANE_TTY = <ContextVar.PANE_TTY: 'pane_tty'>

Pseudo terminal of pane

PANE_WIDTH = <ContextVar.PANE_WIDTH: 'pane_width'>

Width of pane

PID = <ContextVar.PID: 'pid'>

Server PID

RECTANGLE_TOGGLE = <ContextVar.RECTANGLE_TOGGLE: 'rectangle_toggle'>

1 if rectangle selection is activated

SCROLL_POSITION = <ContextVar.SCROLL_POSITION: 'scroll_position'>

Scroll position in copy mode

SCROLL_REGION_LOWER = <ContextVar.SCROLL_REGION_LOWER: 'scroll_region_lower'>

Bottom of scroll region in pane

SCROLL_REGION_UPPER = <ContextVar.SCROLL_REGION_UPPER: 'scroll_region_upper'>

Top of scroll region in pane

SEARCH_MATCH = <ContextVar.SEARCH_MATCH: 'search_match'>

Search match if any

SEARCH_PRESENT = <ContextVar.SEARCH_PRESENT: 'search_present'>

1 if search started in copy mode

SELECTION_ACTIVE = <ContextVar.SELECTION_ACTIVE: 'selection_active'>

1 if selection started and changes with the cursor in copy mode

SELECTION_END_X = <ContextVar.SELECTION_END_X: 'selection_end_x'>

X position of the end of the selection

SELECTION_END_Y = <ContextVar.SELECTION_END_Y: 'selection_end_y'>

Y position of the end of the selection

SELECTION_PRESENT = <ContextVar.SELECTION_PRESENT: 'selection_present'>

1 if selection started in copy mode

SELECTION_START_X = <ContextVar.SELECTION_START_X: 'selection_start_x'>

X position of the start of the selection

SELECTION_START_Y = <ContextVar.SELECTION_START_Y: 'selection_start_y'>

Y position of the start of the selection

SESSION_ACTIVITY = <ContextVar.SESSION_ACTIVITY: 'session_activity'>

Time of session last activity

SESSION_ALERTS = <ContextVar.SESSION_ALERTS: 'session_alerts'>

List of window indexes with alerts

SESSION_ATTACHED = <ContextVar.SESSION_ATTACHED: 'session_attached'>

Number of clients session is attached to

SESSION_ATTACHED_LIST = <ContextVar.SESSION_ATTACHED_LIST: 'session_attached_list'>

List of clients session is attached to

SESSION_CREATED = <ContextVar.SESSION_CREATED: 'session_created'>

Time session created

SESSION_FORMAT = <ContextVar.SESSION_FORMAT: 'session_format'>

1 if format is for a session

SESSION_GROUP = <ContextVar.SESSION_GROUP: 'session_group'>

Name of session group

SESSION_GROUP_ATTACHED = <ContextVar.SESSION_GROUP_ATTACHED: 'session_group_attached'>

Number of clients sessions in group are attached to

SESSION_GROUP_ATTACHED_LIST = <ContextVar.SESSION_GROUP_ATTACHED_LIST: 'session_group_attached_list'>

List of clients sessions in group are attached to

SESSION_GROUP_LIST = <ContextVar.SESSION_GROUP_LIST: 'session_group_list'>

List of sessions in group

SESSION_GROUP_MANY_ATTACHED = <ContextVar.SESSION_GROUP_MANY_ATTACHED: 'session_group_many_attached'>

1 if multiple clients attached to sessions in group

SESSION_GROUP_SIZE = <ContextVar.SESSION_GROUP_SIZE: 'session_group_size'>

Size of session group

SESSION_GROUPED = <ContextVar.SESSION_GROUPED: 'session_grouped'>

1 if session in a group

SESSION_ID = <ContextVar.SESSION_ID: 'session_id'>

Unique session ID

SESSION_LAST_ATTACHED = <ContextVar.SESSION_LAST_ATTACHED: 'session_last_attached'>

Time session last attached

SESSION_MANY_ATTACHED = <ContextVar.SESSION_MANY_ATTACHED: 'session_many_attached'>

1 if multiple clients attached

SESSION_MARKED = <ContextVar.SESSION_MARKED: 'session_marked'>

1 if this session contains the marked pane

SESSION_NAME = <ContextVar.SESSION_NAME: 'session_name'>

Name of session

SESSION_PATH = <ContextVar.SESSION_PATH: 'session_path'>

Working directory of session

SESSION_STACK = <ContextVar.SESSION_STACK: 'session_stack'>

Window indexes in most recent order

SESSION_WINDOWS = <ContextVar.SESSION_WINDOWS: 'session_windows'>

Number of windows in session

SOCKET_PATH = <ContextVar.SOCKET_PATH: 'socket_path'>

Server socket path

START_TIME = <ContextVar.START_TIME: 'start_time'>

Server start time

UID = <ContextVar.UID: 'uid'>

Server UID

USER = <ContextVar.USER: 'user'>

Server user

VERSION = <ContextVar.VERSION: 'version'>

Server version

WINDOW_ACTIVE = <ContextVar.WINDOW_ACTIVE: 'window_active'>

1 if window active

WINDOW_ACTIVE_CLIENTS = <ContextVar.WINDOW_ACTIVE_CLIENTS: 'window_active_clients'>

Number of clients viewing this window

WINDOW_ACTIVE_CLIENTS_LIST = <ContextVar.WINDOW_ACTIVE_CLIENTS_LIST: 'window_active_clients_list'>

List of clients viewing this window

WINDOW_ACTIVE_SESSIONS = <ContextVar.WINDOW_ACTIVE_SESSIONS: 'window_active_sessions'>

Number of sessions on which this window is active

WINDOW_ACTIVE_SESSIONS_LIST = <ContextVar.WINDOW_ACTIVE_SESSIONS_LIST: 'window_active_sessions_list'>

List of sessions on which this window is active

WINDOW_ACTIVITY = <ContextVar.WINDOW_ACTIVITY: 'window_activity'>

Time of window last activity

WINDOW_ACTIVITY_FLAG = <ContextVar.WINDOW_ACTIVITY_FLAG: 'window_activity_flag'>

1 if window has activity

WINDOW_BELL_FLAG = <ContextVar.WINDOW_BELL_FLAG: 'window_bell_flag'>

1 if window has bell

WINDOW_BIGGER = <ContextVar.WINDOW_BIGGER: 'window_bigger'>

1 if window is larger than client

WINDOW_CELL_HEIGHT = <ContextVar.WINDOW_CELL_HEIGHT: 'window_cell_height'>

Height of each cell in pixels

WINDOW_CELL_WIDTH = <ContextVar.WINDOW_CELL_WIDTH: 'window_cell_width'>

Width of each cell in pixels

WINDOW_END_FLAG = <ContextVar.WINDOW_END_FLAG: 'window_end_flag'>

1 if window has the highest index

WINDOW_FLAGS = <ContextVar.WINDOW_FLAGS: 'window_flags'>

Window flags with # escaped as ##

WINDOW_FORMAT = <ContextVar.WINDOW_FORMAT: 'window_format'>

1 if format is for a window

WINDOW_HEIGHT = <ContextVar.WINDOW_HEIGHT: 'window_height'>

Height of window

WINDOW_ID = <ContextVar.WINDOW_ID: 'window_id'>

Unique window ID

WINDOW_INDEX = <ContextVar.WINDOW_INDEX: 'window_index'>

Index of window

WINDOW_LAST_FLAG = <ContextVar.WINDOW_LAST_FLAG: 'window_last_flag'>

1 if window is the last used

WINDOW_LAYOUT = <ContextVar.WINDOW_LAYOUT: 'window_layout'>

Window layout description, ignoring zoomed window panes

WINDOW_LINKED = <ContextVar.WINDOW_LINKED: 'window_linked'>

1 if window is linked across sessions

WINDOW_LINKED_SESSIONS = <ContextVar.WINDOW_LINKED_SESSIONS: 'window_linked_sessions'>

Number of sessions this window is linked to

WINDOW_LINKED_SESSIONS_LIST = <ContextVar.WINDOW_LINKED_SESSIONS_LIST: 'window_linked_sessions_list'>

List of sessions this window is linked to

WINDOW_MARKED_FLAG = <ContextVar.WINDOW_MARKED_FLAG: 'window_marked_flag'>

1 if window contains the marked pane

WINDOW_NAME = <ContextVar.WINDOW_NAME: 'window_name'>

Name of window

WINDOW_OFFSET_X = <ContextVar.WINDOW_OFFSET_X: 'window_offset_x'>

X offset into window if larger than client

WINDOW_OFFSET_Y = <ContextVar.WINDOW_OFFSET_Y: 'window_offset_y'>

Y offset into window if larger than client

WINDOW_PANES = <ContextVar.WINDOW_PANES: 'window_panes'>

Number of panes in window

WINDOW_RAW_FLAGS = <ContextVar.WINDOW_RAW_FLAGS: 'window_raw_flags'>

Window flags with nothing escaped

WINDOW_SILENCE_FLAG = <ContextVar.WINDOW_SILENCE_FLAG: 'window_silence_flag'>

1 if window has silence alert

WINDOW_STACK_INDEX = <ContextVar.WINDOW_STACK_INDEX: 'window_stack_index'>

Index in session most recent stack

WINDOW_START_FLAG = <ContextVar.WINDOW_START_FLAG: 'window_start_flag'>

1 if window has the lowest index

WINDOW_VISIBLE_LAYOUT = <ContextVar.WINDOW_VISIBLE_LAYOUT: 'window_visible_layout'>

Window layout description, respecting zoomed window panes

WINDOW_WIDTH = <ContextVar.WINDOW_WIDTH: 'window_width'>

Width of window

WINDOW_ZOOMED_FLAG = <ContextVar.WINDOW_ZOOMED_FLAG: 'window_zoomed_flag'>

1 if window is zoomed

WRAP_FLAG = <ContextVar.WRAP_FLAG: 'wrap_flag'>

Pane wrap flag

def current_value(self) -> str:
972    def current_value(self) -> str:
973        """
974        Returns the current value of the context variable.
975        """
976        # run shell command to get current value
977        return subprocess.run(["tmux", "display-message", "-p", f"'{str(self)}'"], stdout=subprocess.PIPE).stdout.decode("utf-8").strip()

Returns the current value of the context variable.

Inherited Members
enum.Enum
name
value
def current_values(vars: List[ContextVar]) -> List[str]:
980def current_values(vars: List[ContextVar]) -> List[str]:
981    """
982    Returns the current values of the context variables as a list.
983    More efficient than calling current_value on each variable.
984    """
985    # call string on each variable
986    command = ["tmux", "display-message", "-p",
987               "\n".join([str(var) for var in vars])]
988    proc = subprocess.run(command, stdout=subprocess.PIPE)
989    # split the output and ruturn
990    return proc.stdout.decode("utf-8").strip().split("\n")

Returns the current values of the context variables as a list. More efficient than calling current_value on each variable.