Eclectic Media Git run_in_split / 286747a
Initial commit Ariana Giroux 11 months ago
4 changed file(s) with 108 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 from os import system, environ
1 from click import command, argument, option
2 import shlex
3
4
5 @command()
6 @argument('command')
7 @option('--horizontal', is_flag=True,
8 help='Split pane horizontally.')
9 @option('--sleep', is_flag=True,
10 help='If true, sleep for five seconds after the command exits.')
11 @option('--pause', is_flag=True,
12 help='If true, pause until user presses enter.')
13 @option('--pause-on-error', is_flag=True,
14 help='If true, pause until user presses enter only if the process does '
15 'not exit 0.')
16 def run_in_pane(command, **kwargs):
17 if not list(environ).count('TMUX'):
18 raise RuntimeError('CRITICAL! Must be run within TMUX!')
19
20 executable = 'tmux split-window'
21
22 if list(kwargs).count('horizontal'):
23 if kwargs['horizontal']:
24 executable += ' -h'
25
26 executable += " '{}".format(command)
27 # current command (if "echo hello world"):
28 # tmux split-window 'echo hello world
29
30 if kwargs['sleep']:
31 if kwargs['pause'] or kwargs['pause_on_error']:
32 raise KeyError('Cannot use --sleep in combination with --pause or '
33 '--pause-on-error!')
34
35 executable += "; sleep 5"
36 # current command (if "echo hello world"):
37 # tmux split-window 'echo hello world; sleep 5
38
39 if kwargs['pause']:
40 if kwargs['sleep'] or kwargs['pause_on_error']:
41 raise KeyError('Cannot use --pause in combination with --sleep or '
42 '--pause-on-error!')
43
44 executable += "; read"
45 # current command (if "echo hello world"):
46 # tmux split-window 'echo hello world; read
47
48 if kwargs['pause_on_error']:
49 if kwargs['sleep'] or kwargs['pause']:
50 raise KeyError('Cannot use --pause_on_error in combination with '
51 '--sleep or --pause!')
52
53 executable += "; if [ $? != 0 ]; then read; fi"
54 # current command (if "echo hello world"):
55 # tmux split-window 'echo hello world; if [ $? != 0 ]; then read; fi
56
57 executable += "'" # close command quote
58 system(executable)
59
60 try:
61 run_in_pane()
62 except Exception as e:
63 print(str(e))
0 [aliases]
1 test=pytest
0 from setuptools import setup, find_packages
1
2 # with open("docs/README.rst", "r") as fh:
3 # long_description = fh.read()
4
5 with open("requirements.txt", "r") as f:
6 required = f.read().splitlines()
7
8 setup(
9 name='run_in_split',
10 version=0.1,
11 description='Simple utility to run command in tmux pane, with wait conditions.',
12 # long_description=long_description,
13 # long_description_content_type="text/x-rst",
14 url='git://eclecticmedia.space/arianagiroux/run_in_split',
15 author='Ariana Giroux',
16 author_email='ariana.giroux@gmail.com',
17 license='MIT',
18 packages=find_packages(),
19 setup_requires=["pytest-runner"],
20 tests_require=["pytest"],
21 install_requires=required,
22 zip_safe=True,
23 entry_points={
24 'console_scripts': ['run_in_split=run_in_split:__main__'],
25 },
26 classifiers=(
27 "Programming Language :: Python :: 3",
28 "License :: OSI Approved :: MIT License",
29 "Operating System :: OS Independent",
30 "Development Status :: 4 - Beta",
31 "Environment :: Console",
32 "Intended Audience :: Developers",
33 "Intended Audience :: End Users/Desktop",
34 "Intended Audience :: Information Technology",
35 "License :: OSI Approved :: MIT License",
36 "Operating System :: Unix",
37 "Topic :: System :: Networking :: Monitoring",
38 "Topic :: Utilities",
39 ),
40 )