@@ -84,7 +84,13 @@ Now, let's open a tmux session.
8484
8585.. code-block :: bash
8686
87- $ tmux
87+ $ tmux new-session -n tmuxp_wins -s a_tmuxp_session
88+
89+ Why not just ``$ tmux ``? We will assume you want to see the tmux changes
90+ in the current tmux session. So we will use:
91+
92+ Window name: ``tmuxp_wins ``
93+ Session name: ``a_tmuxp_session ``
8894
8995We are inside of a tmux session, let's launch our python interpretter
9096(``$ python ``, ``$ bpython `` or ``$ ipython ``) and begin issuing commands
@@ -102,6 +108,9 @@ First, we can grab a :class:`Server`.
102108.. code-block :: python
103109
104110 server = tmuxp.Server()
111+ >> > server
112+ < tmuxp.server.Server object at 0x 7fbd622c1dd0>
113+
105114
106115 .. note ::
107116
@@ -112,5 +121,117 @@ First, we can grab a :class:`Server`.
112121``server `` is now a living object bound to the tmux server's Sessions,
113122Windows and Panes.
114123
124+ Find your :class: `Session `
125+ --------------------------
126+
127+ .. todo ::
128+ Update API to catch the ENV variables for the current ``TMUX `` socket,
129+ and allow a quick option to grab the current tmux's environment's
130+ :class: `Server `, :class: `Window ` and :class: `Pane ` via CLI.
131+
132+ If you have multiple tmux session's open. You can see that all of the
133+ methods in :class: `Server ` are available.
134+
135+ We can list sessions with :meth: `Server.list_sessions `:
136+
137+ .. code-block :: python
138+
139+ >> > server.list_sessions()
140+ [Session($ 3 a_tmuxp_session), Session($ 1 tmuxp)]
141+
142+ This returns a list of :class: `Session ` objects you can grab. You could
143+ our current session with:
144+
145+ .. code-block :: python
146+
147+ >> > server.list_sessions()[0 ]
148+
149+ That's not guaranteed. tmuxp works against current tmux information, the
150+ session's name could be changed, or another tmux session may be created,
151+ so :meth: `Server.getById ` and :meth: `Server.findWhere ` exists as a lookup:
152+
153+ Get session by ID
154+ -----------------
155+
156+ tmux sessions use the ``$[0-9] `` convention as a way to identify sessions.
157+
158+ ``$3 `` is whatever the ID ``list_sessions() `` returned above.
159+
160+ .. code-block :: python
161+
162+
163+ >> > server.getById(' $3' )
164+ Session($ 3 a_tmuxp_session)
165+
166+ You may ``session = getById('$<yourId>') `` to use the session object.
167+
168+ Get session by nane / other properties
169+ --------------------------------------
170+
171+ I really like `Backbone `_'s approach to handling collections of structured
172+ data. So I made a :meth: `Server.findWhere ` method modelled after
173+ `Backbone.Collection.prototype.findWhere `_.
174+
175+ .. code-block :: python
176+
177+ >> > server.findWhere({ " session_name" : " a_tmuxp_session" })
178+ Session($ 3 a_tmuxp_session)
179+
180+ With ``findWhere ``, pass in a dict and return the first object found. In
181+ this case, a :class: `Server ` holds a collection of child :class: `Session `.
182+ :class: `Session ` and :class: `Window ` both utilize ``findWhere `` to sift
183+ through Windows and Panes, respectively.
184+
185+ So you may now use:
186+
187+ .. code-block :: python
188+
189+ >> > session = server.findWhere({ " session_name" : " a_tmuxp_session" })
190+
191+ to give us a ``session `` object to play with.
192+
193+ Playing with our tmux session
194+ -----------------------------
195+
196+ .. todo ::
197+
198+ Consider migrating tmuxp to use a ``.execute `` sqlalchemy style and have
199+ commands such as ``new_window() `` return CLI output. Also tmuxp could use
200+ use "engine" as a way to control if it's using socket's or shell commands
201+ to handle tmux.
202+
203+ We now have access to ``session `` from above with all of the methods
204+ available in :class: `Session `.
205+
206+ Let's make a :meth: `Session.new_window `, in the background:
207+
208+ .. code-block :: python
209+
210+ >> > session.new_window(attach = False , window_name = " ha in the bg" )
211+ Window(@ 8 2 :ha in the bg, Session($ 3 a_tmuxp_session))
212+
213+ So a few things:
214+
215+ 1. ``attach=False `` meant to create a new window, but not to switch to it.
216+ It is the same as ``$ tmux new-window -d ``.
217+ 2. ``window_name `` may be specified.
218+ 3. Returns the :class: `Window ` object created.
219+
220+ .. note ::
221+
222+ In any of the cases, you can look up the detailed :ref: `api ` to see all
223+ the options you have.
224+
225+ Let's delete that window (:meth: `Session.kill_window `).
226+
227+ Method 1: Use passthrough to tmux's ``target `` system.
228+
229+ .. code-block :: python
230+
231+ >> > session.kill_window(" ha in" )
232+
233+ .. code-block ::
115234
116235 .. _sliderepl : http://discorporate.us/projects/sliderepl/
236+ .. _backbone : http:/ /backbonejs.org
237+ .. _Backbone.Collection.prototype.findWhere : http://backbonejs.org/#Collection-findWhere
0 commit comments