Skip to content

Commit 50b6ed6

Browse files
committed
docs: Usage updates
1 parent 0b3e388 commit 50b6ed6

File tree

1 file changed

+35
-102
lines changed

1 file changed

+35
-102
lines changed

doc/quickstart.rst

Lines changed: 35 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,6 @@ sessions using python code.
1010
In this example, we will launch a tmux session and control the windows
1111
from inside a live tmux session.
1212

13-
14-
Setting up tab-completion
15-
-------------------------
16-
17-
To begin, it's preferable to install a python CLI with tab-completion.
18-
19-
You can install a custom python shell like `bpython`_ or `iPython`_, which
20-
has some awesome CLI features, or setup vanilla :py:mod:`readline` support.
21-
22-
``readline`` tab-completion
23-
"""""""""""""""""""""""""""
24-
25-
.. seealso::
26-
Source: `How do I add tab-completion to the python shell`_ on
27-
`StackOverflow`_.
28-
29-
Create ``~.pythonrc`` in ``$HOME`` folder:
30-
31-
.. code-block:: python
32-
33-
# ~/.pythonrc
34-
# enable syntax completion
35-
try:
36-
import readline
37-
except ImportError:
38-
print "Module readline not available."
39-
else:
40-
import rlcompleter
41-
readline.parse_and_bind("tab: complete")
42-
43-
Then in your ``.bashrc`` or ``.zshrc`` file, add:
44-
45-
.. code-block:: bash
46-
47-
export PYTHONSTARTUP=~/.pythonrc
48-
49-
.. _How do I add tab-completion to the python shell: http://stackoverflow.com/a/246779
50-
.. _StackOverflow: http://www.stackoverflow.com
51-
52-
bpython or ipython cli
53-
""""""""""""""""""""""
54-
55-
`bpython`_ can be installed with ``$ [sudo] pip install bpython`` and
56-
`ipython`_ can be installed with ``$ [sudo] pip install ipython``.
57-
58-
bpython allows using ``<F2>`` to see the source of CLI methods in colors.
59-
60-
.. todo::
61-
If you know any extra benefits of ipython or bpython for CLI and could
62-
list them here please edit this page.
63-
64-
65-
.. _bpython: https://bitbucket.org/bobf/bpython
66-
.. _ipython: http://ipython.org
67-
6813
Control tmux via python
6914
-----------------------
7015

@@ -84,27 +29,29 @@ Now, let's open a tmux session.
8429

8530
.. code-block:: bash
8631
87-
$ tmux new-session -n libtmux_wins -s a_libtmux_session
32+
$ tmux new-session -n bar -s foo
8833
8934
Why not just ``$ tmux``? We will assume you want to see the tmux changes
9035
in the current tmux session. So we will use:
9136

92-
Window name: ``libtmux_wins``
93-
Session name: ``a_libtmux_session``
94-
95-
We are inside of a tmux session, let's launch our python interpretter
96-
(``$ python``, ``$ bpython`` or ``$ ipython``) and begin issuing commands
97-
to libtmux CLI style. For this I'll use ``python``.
37+
Window name: ``bar``
38+
Session name: ``foo``
9839

9940
.. code-block:: bash
10041
10142
$ python
10243
44+
For commandline completion, you can also use `ptpython`_.
45+
46+
.. code-block:: bash
47+
48+
$ [sudo] pip install ptpython
49+
$ ptpython
50+
10351
.. module:: libtmux
10452

10553
First, we can grab a :class:`Server`.
10654

107-
10855
.. code-block:: python
10956
11057
>>> import libtmux
@@ -125,11 +72,6 @@ Windows and Panes.
12572
Find your :class:`Session`
12673
--------------------------
12774

128-
.. todo::
129-
Update API to catch the ENV variables for the current ``TMUX`` socket,
130-
and allow a quick option to grab the current tmux's environment's
131-
:class:`Server`, :class:`Window` and :class:`Pane` via CLI.
132-
13375
If you have multiple tmux sessions open, you can see that all of the
13476
methods in :class:`Server` are available.
13577

@@ -138,7 +80,7 @@ We can list sessions with :meth:`Server.list_sessions`:
13880
.. code-block:: python
13981
14082
>>> server.list_sessions()
141-
[Session($3 a_libtmux_session), Session($1 libtmux)]
83+
[Session($3 foo), Session($1 libtmux)]
14284
14385
This returns a list of :class:`Session` objects you can grab. We can
14486
find our current session with:
@@ -162,7 +104,7 @@ tmux sessions use the ``$[0-9]`` convention as a way to identify sessions.
162104
163105
164106
>>> server.getById('$3')
165-
Session($3 a_libtmux_session)
107+
Session($3 foo)
166108
167109
You may ``session = getById('$<yourId>')`` to use the session object.
168110

@@ -175,8 +117,8 @@ data. So I made a :meth:`Server.findWhere` method modelled after
175117

176118
.. code-block:: python
177119
178-
>>> server.findWhere({ "session_name": "a_libtmux_session" })
179-
Session($3 a_libtmux_session)
120+
>>> server.findWhere({ "session_name": "foo" })
121+
Session($3 foo)
180122
181123
With ``findWhere``, pass in a dict and return the first object found. In
182124
this case, a :class:`Server` holds a collection of child :class:`Session`.
@@ -187,20 +129,13 @@ So you may now use:
187129

188130
.. code-block:: python
189131
190-
>>> session = server.findWhere({ "session_name": "a_libtmux_session" })
132+
>>> session = server.findWhere({ "session_name": "foo" })
191133
192134
to give us a ``session`` object to play with.
193135

194136
Playing with our tmux session
195137
-----------------------------
196138

197-
.. todo::
198-
199-
Consider migrating libtmux to use a ``.execute`` sqlalchemy style and have
200-
commands such as ``new_window()`` return CLI output. Also libtmux could
201-
use "engine" as a way to control if it's using a socket or shell commands
202-
to handle tmux.
203-
204139
We now have access to ``session`` from above with all of the methods
205140
available in :class:`Session`.
206141

@@ -209,7 +144,7 @@ Let's make a :meth:`Session.new_window`, in the background:
209144
.. code-block:: python
210145
211146
>>> session.new_window(attach=False, window_name="ha in the bg")
212-
Window(@8 2:ha in the bg, Session($3 a_libtmux_session))
147+
Window(@8 2:ha in the bg, Session($3 foo))
213148
214149
So a few things:
215150

@@ -220,8 +155,7 @@ So a few things:
220155

221156
.. note::
222157

223-
In any of the cases, you can look up the detailed :ref:`api` to see all
224-
the options you have.
158+
Use the API reference :ref:`api` for more commands.
225159

226160
Let's delete that window (:meth:`Session.kill_window`).
227161

@@ -231,30 +165,30 @@ Method 1: Use passthrough to tmux's ``target`` system.
231165
232166
>>> session.kill_window("ha in")
233167
234-
The window in the bg dissappeared. This was the equivalent of ``$ tmux kill-window -t'ha in'``
168+
The window in the bg dissappeared. This was the equivalent of
169+
``$ tmux kill-window -t'ha in'``
235170

236-
Internally, tmux uses ``target``. Its specific behavior depends on what the target is, view the tmux manpage for more information.
171+
Internally, tmux uses ``target``. Its specific behavior depends on what the
172+
target is, view the tmux manpage for more information::
237173

238-
This section contains a list of the commands supported by tmux. Most commands accept the optional -t argument with one of target-client, target-session target-window, or target-pane.
174+
This section contains a list of the commands supported by tmux. Most commands
175+
accept the optional -t argument with one of target-client, target-session,
176+
target-window, or target-pane.
239177

240-
In this case, you can also go back in time and recreate the window again. The CLI should have history, so navigate up with the arrow key.
178+
In this case, you can also go back in time and recreate the window again. The CLI
179+
should have history, so navigate up with the arrow key.
241180

242181
.. code-block:: python
243182
244183
>>> session.new_window(attach=False, window_name="ha in the bg")
245-
Window(@11 3:ha in the bg, Session($3 a_libtmux_session))
184+
Window(@11 3:ha in the bg, Session($3 foo))
246185
247186
Try to kill the window by the matching id ``@[0-9999]``.
248187

249188
.. code-block:: python
250189
251190
>>> session.new_window(attach=False, window_name="ha in the bg")
252-
Window(@12 3:ha in the bg, Session($3 a_libtmux_session))
253-
254-
255-
.. code-block:: python
256-
257-
>>> session.kill_window('@12')
191+
Window(@12 3:ha in the bg, Session($3 foo))
258192
259193
In addition, you could also ``.kill_window`` direction from the :class:`Window`
260194
object:
@@ -269,8 +203,8 @@ And kill:
269203
270204
>>> window.kill_window()
271205
272-
And of course, you can use :meth:`Session.list_windows()` and :meth:`Session.findWhere()`
273-
to list and sort through active :class:`Window`'s.
206+
Use :meth:`Session.list_windows()` and :meth:`Session.findWhere()` to list and sort
207+
through active :class:`Window`'s.
274208

275209
Manipulating windows
276210
--------------------
@@ -289,7 +223,7 @@ Let's create a pane, :meth:`Window.split_window`:
289223
.. code-block:: python
290224
291225
>>> window.split_window(attach=False)
292-
Pane(%23 Window(@10 1:libtmux_wins, Session($3 a_libtmux_session)))
226+
Pane(%23 Window(@10 1:bar, Session($3 foo)))
293227
294228
Powered up. Let's have a break down:
295229

@@ -302,7 +236,7 @@ Also, since you are aware of this power, let's commemorate the experience:
302236
.. code-block:: python
303237
304238
>>> window.rename_window('libtmuxower')
305-
Window(@10 1:libtmuxower, Session($3 a_libtmux_session))
239+
Window(@10 1:libtmuxower, Session($3 foo))
306240
307241
You should have noticed :meth:`Window.rename_window` renamed the window.
308242

@@ -326,8 +260,6 @@ can also use the ``.select_*`` available on the object, in this case the pane ha
326260
>>> pane = window.split_window(attach=False)
327261
>>> pane.select_pane()
328262
329-
.. note:: There is much, much more. Take a look at the :ref:`API` and the `testsuite`_.
330-
331263
.. todo:: create a ``kill_pane()`` method.
332264
.. todo:: have a ``.kill()`` and ``.select()`` proxy for Server, Session, Window and Pane objects.
333265

@@ -367,10 +299,11 @@ sessions in the background. :)
367299
.. seealso::
368300

369301
If you want to dig deeper, check out :ref:`API`, the code for
370-
and our `testsuite`_ (see :ref:`developing`.)
302+
and our `test suite`_ (see :ref:`developing`.)
371303

372304
.. _sliderepl: http://discorporate.us/projects/sliderepl/
373305
.. _backbone: http:/ /backbonejs.org
374306
.. _Backbone.Collection.prototype.findWhere: http://backbonejs.org/#Collection-findWhere
375307
.. _workspacebuilder.py: https://github.com/tony/libtmux/blob/master/libtmux/workspacebuilder.py
376-
.. _testsuite: https://github.com/tony/libtmux/tree/master/libtmux/testsuite
308+
.. _test suite: https://github.com/tony/libtmux/tree/master/tests
309+
.. _ptpython: https://github.com/jonathanslenders/ptpython

0 commit comments

Comments
 (0)