Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ $ terminator-split --help
usage:
terminator-split [-h] [-d]
[-e COMMAND] [-g CONFIG] [-t TERMINATOR]
[-f TEXT_SIZE]
[TERMINATOR_OPTIONS]
hostname [hostname ...]

terminator-split [-h] [-d]
[-g CONFIG] [-t TERMINATOR] [-s SHELL]
[-f TEXT_SIZE]
[TERMINATOR_OPTIONS]
number

Expand All @@ -25,6 +27,14 @@ optional arguments:
-g CONFIG, --config CONFIG Use this terminator config file
-s SHELL, --shell SHELL Specify the shell to be loaded
-t TERMINATOR, --terminator TERMINATOR
-f TEXT_SIZE, --text-size TEXT_SIZE
terminal font size in points
```

Example with a larger font:

```shell
terminator-split -f 14 -m server1 server2 server3 server4
```

```shell
Expand Down
44 changes: 42 additions & 2 deletions terminator-split
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ https://github.com/AlekseyChudov/terminator-split
import argparse
import logging
import os
import re
import resource
import tempfile

import configobj

__author__ = 'Aleksey Chudov <aleksey.chudov@gmail.com>'
__date__ = '23 Nov 2018'
__version__ = '1.0.4'
__version__ = '1.0.5'


class TerminatorSplit(object):
Expand All @@ -25,7 +26,8 @@ class TerminatorSplit(object):
'config': os.path.expanduser('~/.config/terminator/config'),
'command': "ssh '{}'",
'shell': 'bash -l',
'terminator': '/usr/bin/terminator'
'terminator': '/usr/bin/terminator',
'text_size': None,
}

def __init__(self):
Expand All @@ -40,11 +42,13 @@ class TerminatorSplit(object):
usage = """
terminator-split [-h] [-d]
[-e COMMAND] [-g CONFIG] [-t TERMINATOR]
[-f TEXT_SIZE]
[TERMINATOR_OPTIONS]
hostname [hostname ...]

terminator-split [-h] [-d]
[-g CONFIG] [-t TERMINATOR] [-s SHELL]
[-f TEXT_SIZE]
[TERMINATOR_OPTIONS]
number
"""
Expand All @@ -55,6 +59,7 @@ class TerminatorSplit(object):
parser.add_argument('-g', '--config', help='Use this terminator config file')
parser.add_argument('-s', '--shell', help='Specify the shell to be loaded')
parser.add_argument('-t', '--terminator')
parser.add_argument('-f', '--font-size', dest='text_size', help='terminal font size')
parser.add_argument('hostname', nargs='+')
namespace = argparse.Namespace(**self.DEFAULT)
args, unknown_args = parser.parse_known_args(namespace=namespace)
Expand All @@ -71,8 +76,43 @@ class TerminatorSplit(object):
logging.debug('args:{}'.format(self._args))
logging.debug('unknown_args:{}'.format(self._unknown_args))

@staticmethod
def _config_bool(value, default=False):
if isinstance(value, bool):
return value
if value is None:
return default
return str(value).lower() in ('true', 'yes', '1', 'on')

@staticmethod
def _replace_font_size(font, size):
font = font.strip()
match = re.match(r'^(.*?)\s+(\d+(?:\.\d+)?)\s*$', font)
if match:
return '{} {}'.format(match.group(1), size)
return '{} {}'.format(font, size)

def _apply_text_size(self, config):
size = self._args.text_size
profiles = config.get('profiles')
if not profiles:
profiles = config['profiles'] = {}

for profile in profiles.values():
if not hasattr(profile, 'get'):
continue
if self._config_bool(profile.get('use_system_font'), default=True):
font = 'Monospace {}'.format(size)
else:
font = profile.get('font', 'Monospace 10')
font = self._replace_font_size(font, size)
profile['font'] = font
profile['use_system_font'] = False

def _write_config(self):
config = configobj.ConfigObj(self._args.config)
if self._args.text_size is not None:
self._apply_text_size(config)
self._update_layout(config)
with tempfile.NamedTemporaryFile(delete=False) as tmp:
config.filename = tmp.name
Expand Down