Skip to content

Commit 19b507e

Browse files
authored
Shell: Consolidate shell_plus, rich shell detection (#641)
Deprecate shell_plus into shell, pick best shell by default, allow passing custom shell
2 parents be35db2 + 8226759 commit 19b507e

File tree

8 files changed

+464
-213
lines changed

8 files changed

+464
-213
lines changed

CHANGES

+22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ Here you can find the recent changes to tmuxp
77
current
88
-------
99
- *Insert changes/features/fixes for next release here*
10+
- :issue:`641` Improvements to ``shell``
11+
12+
Thanks `django-extensions`_ (licensed MIT) for the shell detection abstraction.
13+
14+
- Deprecate ``shell_plus``
15+
- ``tmuxp shell`` now detects the best shell available by default
16+
- Python 3.7+ with ``PYTHONBREAKPOINT`` set in env will drop into ``pdb`` by
17+
default
18+
- Drop into ``code.interact`` by default instead of ``pdb`` if no third
19+
party shells found
20+
- New options, override:
21+
22+
- ``--pdb``: Use plain old ``breakpoint()`` (python 3.7+) or
23+
``pdb.set_trace``
24+
- ``--code``: Drop into ``code.interact``, accepts ``--use-pythonrc``
25+
- ``--bpython``: Drop into bpython
26+
- ``--ipython``: Drop into ipython
27+
- ``--ptpython``: Drop into ptpython, accepts ``--use-vi-mode``
28+
- ``--ptipython``: Drop into ipython + ptpython, accepts
29+
``--use-vi-mode``
30+
31+
.. _django-extensions: https://github.com/django-extensions/django-extensions
1032

1133
tmuxp 1.6.0 (2020-11-06)
1234
------------------------

docs/api.rst

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ Internals
1515

1616
.. automethod:: tmuxp.util.run_before_script
1717

18+
.. automethod:: tmuxp.util.oh_my_zsh_auto_title
19+
20+
.. automethod:: tmuxp.util.raise_if_tmux_not_running
21+
22+
.. automethod:: tmuxp.util.get_current_pane
23+
24+
.. automethod:: tmuxp.util.get_session
25+
26+
.. automethod:: tmuxp.util.get_window
27+
28+
.. automethod:: tmuxp.util.get_pane
29+
1830
CLI
1931
---
2032

docs/cli.rst

+14
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ this via ``tmuxp -c``:
101101
.. _ipdb: https://pypi.org/project/ipdb/
102102
.. _libtmux: https://libtmux.git-pull.com
103103

104+
Shell detection
105+
~~~~~~~~~~~~~~~
106+
107+
``tmuxp shell`` detects the richest shell available in your *site packages*, you can also pick your shell via args:
108+
109+
- ``--pdb``: Use plain old ``breakpoint()`` (python 3.7+) or
110+
``pdb.set_trace``
111+
- ``--code``: Drop into ``code.interact``, accepts ``--use-pythonrc``
112+
- ``--bpython``: Drop into bpython
113+
- ``--ipython``: Drop into ipython
114+
- ``--ptpython``: Drop into ptpython, accepts ``--use-vi-mode``
115+
- ``--ptipython``: Drop into ipython + ptpython, accepts
116+
``--use-vi-mode``
117+
104118
.. _cli_freeze:
105119

106120
Freeze sessions

tests/test_cli.py

+31-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import libtmux
1414
from libtmux.common import has_lt_version
1515
from libtmux.exc import LibTmuxException
16-
from tmuxp import cli, config
16+
from tmuxp import cli, config, exc
1717
from tmuxp.cli import (
1818
command_ls,
1919
get_config_dir,
@@ -407,7 +407,7 @@ def test_load_zsh_autotitle_warning(cli_args, tmpdir, monkeypatch):
407407
assert 'Please set' not in result.output
408408

409409

410-
@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
410+
@pytest.mark.parametrize("cli_cmd", ['shell', ('shell', '--pdb')])
411411
@pytest.mark.parametrize(
412412
"cli_args,inputs,env,expected_output",
413413
[
@@ -501,7 +501,8 @@ def test_shell(
501501
SERVER_SOCKET_NAME=server.socket_name,
502502
)
503503

504-
cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
504+
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
505+
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
505506

506507
for k, v in env.items():
507508
monkeypatch.setenv(k, v.format(**template_ctx))
@@ -515,7 +516,13 @@ def test_shell(
515516
assert expected_output.format(**template_ctx) in result.output
516517

517518

518-
@pytest.mark.parametrize("cli_cmd", ['shell', 'shell_plus'])
519+
@pytest.mark.parametrize(
520+
"cli_cmd",
521+
[
522+
'shell',
523+
('shell', '--pdb'),
524+
],
525+
)
519526
@pytest.mark.parametrize(
520527
"cli_args,inputs,env,template_ctx,exception,message",
521528
[
@@ -537,7 +544,7 @@ def test_shell(
537544
[],
538545
{},
539546
{'session_name': 'nonexistant_session'},
540-
None,
547+
exc.TmuxpException,
541548
'Session not found: nonexistant_session',
542549
),
543550
(
@@ -551,7 +558,7 @@ def test_shell(
551558
[],
552559
{},
553560
{'window_name': 'nonexistant_window'},
554-
None,
561+
exc.TmuxpException,
555562
'Window not found: {WINDOW_NAME}',
556563
),
557564
],
@@ -583,7 +590,8 @@ def test_shell_target_missing(
583590
PANE_ID=template_ctx.get('pane_id'),
584591
SERVER_SOCKET_NAME=server.socket_name,
585592
)
586-
cli_args = [cli_cmd] + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
593+
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
594+
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
587595

588596
for k, v in env.items():
589597
monkeypatch.setenv(k, v.format(**template_ctx))
@@ -603,12 +611,23 @@ def test_shell_target_missing(
603611
assert message.format(**template_ctx) in result.output
604612

605613

614+
@pytest.mark.parametrize(
615+
"cli_cmd",
616+
[
617+
# 'shell',
618+
# ('shell', '--pdb'),
619+
('shell', '--code'),
620+
# ('shell', '--bpython'),
621+
# ('shell', '--ptipython'),
622+
# ('shell', '--ptpython'),
623+
# ('shell', '--ipython'),
624+
],
625+
)
606626
@pytest.mark.parametrize(
607627
"cli_args,inputs,env,message",
608628
[
609629
(
610630
[
611-
'shell_plus',
612631
'-L{SOCKET_NAME}',
613632
],
614633
[],
@@ -617,7 +636,6 @@ def test_shell_target_missing(
617636
),
618637
(
619638
[
620-
'shell_plus',
621639
'-L{SOCKET_NAME}',
622640
],
623641
[],
@@ -627,6 +645,7 @@ def test_shell_target_missing(
627645
],
628646
)
629647
def test_shell_plus(
648+
cli_cmd,
630649
cli_args,
631650
inputs,
632651
env,
@@ -650,7 +669,9 @@ def test_shell_plus(
650669
SERVER_SOCKET_NAME=server.socket_name,
651670
)
652671

653-
cli_args[:] = [cli_arg.format(**template_ctx) for cli_arg in cli_args]
672+
cli_cmd = list(cli_cmd) if isinstance(cli_cmd, (list, tuple)) else [cli_cmd]
673+
cli_args = cli_cmd + [cli_arg.format(**template_ctx) for cli_arg in cli_args]
674+
654675
for k, v in env.items():
655676
monkeypatch.setenv(k, v.format(**template_ctx))
656677

tests/test_shell.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from tmuxp import shell
2+
from tmuxp._compat import string_types
3+
4+
5+
def test_detect_best_shell():
6+
result = shell.detect_best_shell()
7+
assert isinstance(result, string_types)
8+
9+
10+
def test_shell_detect():
11+
assert isinstance(shell.has_bpython(), bool)
12+
assert isinstance(shell.has_ipython(), bool)
13+
assert isinstance(shell.has_ptpython(), bool)
14+
assert isinstance(shell.has_ptipython(), bool)

0 commit comments

Comments
 (0)