|
| 1 | +.. _Properties: |
| 2 | + |
| 3 | +========== |
| 4 | +Properties |
| 5 | +========== |
| 6 | + |
| 7 | +Get access to the data attributions behind tmux sessions, windows and panes. |
| 8 | + |
| 9 | +This is done through accessing the `formats`_ available in ``list-sessions``, |
| 10 | +``list-windows`` and ``list-panes``. |
| 11 | + |
| 12 | +open two terminals: |
| 13 | + |
| 14 | +terminal one: start tmux in a seperate terminal:: |
| 15 | + |
| 16 | + $ tmux |
| 17 | + |
| 18 | +.. NOTE:: |
| 19 | + |
| 20 | + Make sure you have :ref:`libtmux installed <installation>`:: |
| 21 | + |
| 22 | + pip install libtmux |
| 23 | + |
| 24 | + To upgrade: |
| 25 | + |
| 26 | + pip install -U libtmux |
| 27 | + |
| 28 | +terminal two, ``python`` or ``ptpython`` if you have it:: |
| 29 | + |
| 30 | + $ python |
| 31 | + |
| 32 | +import tmux:: |
| 33 | + |
| 34 | + import tmux |
| 35 | + |
| 36 | +attach default tmux :class:`libtmux.Server` to ``t``:: |
| 37 | + |
| 38 | + >>> t = libtmux.Server(); |
| 39 | + >>> t |
| 40 | + <libtmux.server.Server object at 0x10edd31d0> |
| 41 | + |
| 42 | +Session |
| 43 | +------- |
| 44 | + |
| 45 | +get our ``session`` object:: |
| 46 | + |
| 47 | + >>> session = t.sessions[0] |
| 48 | + |
| 49 | + >>> session |
| 50 | + Session($0 libtmux) |
| 51 | + |
| 52 | +quick access to basic attributes:: |
| 53 | + |
| 54 | + >>> session.name |
| 55 | + u'libtmux' |
| 56 | + |
| 57 | + >>> session.id |
| 58 | + u'$0' |
| 59 | + |
| 60 | + >>> session.width |
| 61 | + u'213' |
| 62 | + |
| 63 | + >>> session.height |
| 64 | + u'114' |
| 65 | + |
| 66 | +to see all attributes for a session:: |
| 67 | + |
| 68 | + >>> session._info.keys() |
| 69 | + [u'session_height', u'session_windows', u'session_width', u'session_id', u'session_created', u'session_attached', u'session_grouped', u'session_name'] |
| 70 | + |
| 71 | + >>> session._info |
| 72 | + {u'session_height': u'114', u'session_windows': u'3', u'session_width': u'213', u'session_id': u'$0', u'session_created': u'1464905357', u'session_attached': u'1', u'session_grouped': u'0', u'session_name': u'libtmux'} |
| 73 | + |
| 74 | + |
| 75 | +some may conflict with python API, to access them, you can use ``.get()``, to get the count |
| 76 | +of sessions in a window:: |
| 77 | + |
| 78 | + >>> session.get('session_windows') |
| 79 | + u'3' |
| 80 | + |
| 81 | +Windows |
| 82 | +------- |
| 83 | + |
| 84 | +The same concepts apply for window:: |
| 85 | + |
| 86 | + >>> window = session.attached_window |
| 87 | + |
| 88 | + >>> window |
| 89 | + Window(@2 2:docs, Session($0 libtmux)) |
| 90 | + |
| 91 | +basics:: |
| 92 | + |
| 93 | + >>> window.name |
| 94 | + u'docs' |
| 95 | + |
| 96 | + >>> window.id |
| 97 | + u'@2' |
| 98 | + |
| 99 | + >>> window.height |
| 100 | + u'114' |
| 101 | + |
| 102 | + >>> window.width |
| 103 | + u'213' |
| 104 | + |
| 105 | +everything available:: |
| 106 | + |
| 107 | + >>> window._info |
| 108 | + {u'window_panes': u'4', u'window_active': u'1', u'window_height': u'114', u'window_activity_flag': u'0', u'window_width': u'213', u'session_id': u'$0', u'window_id': u'@2', u'window_layout': u'dad5,213x114,0,0[213x60,0,0,4,213x53,0,61{70x53,0,61,5,70x53,71,61,6,71x53,142,61,7}]', u'window_silence_flag': u'0', u'window_index': u'2', u'window_bell_flag': u'0', u'session_name': u'libtmux', u'window_flags': u'*', u'window_name': u'docs'} |
| 109 | + |
| 110 | + >>> window.keys() |
| 111 | + [u'window_panes', u'window_active', u'window_height', u'window_activity_flag', u'window_width', u'session_id', u'window_id', u'window_layout', u'window_silence_flag', u'window_index', u'window_bell_flag', u'session_name', u'window_flags', u'window_name'] |
| 112 | + |
| 113 | +use ``get()`` for details not accessible via properties:: |
| 114 | + |
| 115 | + >>> pane.get('window_panes') |
| 116 | + u'4' |
| 117 | + |
| 118 | +Panes |
| 119 | +----- |
| 120 | + |
| 121 | +get our pane:: |
| 122 | + |
| 123 | + >>> pane = window.attached_pane |
| 124 | + |
| 125 | + >>> pane |
| 126 | + Pane(%5 Window(@2 2:docs, Session($0 libtmux))) |
| 127 | + |
| 128 | +basics:: |
| 129 | + |
| 130 | + >>> pane.current_command |
| 131 | + u'python' |
| 132 | + |
| 133 | + >>> pane.height |
| 134 | + u'53' |
| 135 | + |
| 136 | + >>> pane.width |
| 137 | + u'70' |
| 138 | + |
| 139 | + >>> pane.index |
| 140 | + u'1' |
| 141 | + |
| 142 | +everything:: |
| 143 | + |
| 144 | + >>> pane._info |
| 145 | + {u'alternate_saved_x': u'0', u'alternate_saved_y': u'0', u'cursor_y': u'47', u'cursor_x': u'0', u'pane_in_mode': u'0', u'insert_flag': u'0', u'keypad_flag': u'0', u'cursor_flag': u'1', u'pane_current_command': u'python', u'window_index': u'2', u'history_size': u'216', u'scroll_region_lower': u'52', u'keypad_cursor_flag': u'0', u'history_bytes': u'38778', u'pane_active': u'1', u'pane_dead': u'0', u'pane_synchronized': u'0', u'window_id': u'@2', u'pane_index': u'1', u'pane_width': u'70', u'mouse_any_flag': u'0', u'mouse_button_flag': u'0', u'window_name': u'docs', u'pane_current_path': u'/Users/me/work/python/libtmux/doc', u'pane_tty': u'/dev/ttys007', u'pane_title': u'Python REPL (ptpython)', u'session_id': u'$0', u'alternate_on': u'0', u'mouse_standard_flag': u'0', u'wrap_flag': u'1', u'history_limit': u'2000', u'pane_pid': u'37172', u'pane_height': u'53', u'session_name': u'libtmux', u'scroll_region_upper': u'0', u'pane_id': u'%5'} |
| 146 | + |
| 147 | + >>> pane._info.keys() |
| 148 | + [u'alternate_saved_x', u'alternate_saved_y', u'cursor_y', u'cursor_x', u'pane_in_mode', u'insert_flag', u'keypad_flag', u'cursor_flag', u'pane_current_command', u'window_index', u'history_size', u'scroll_region_lower', u'keypad_cursor_flag', u'history_bytes', u'pane_active', u'pane_dead', u'pane_synchronized', u'window_id', u'pane_index', u'pane_width', u'mouse_any_flag', u'mouse_button_flag', u'window_name', u'pane_current_path', u'pane_tty', u'pane_title', u'session_id', u'alternate_on', u'mouse_standard_flag', u'wrap_flag', u'history_limit', u'pane_pid', u'pane_height', u'session_name', u'scroll_region_upper', u'pane_id'] |
| 149 | + |
| 150 | +use ``get()`` for details keys:: |
| 151 | + |
| 152 | + >>> pane.get('pane_width') |
| 153 | + u'70' |
| 154 | + |
| 155 | +.. _formats: http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#FORMAT |
0 commit comments