2020-04-05 14:36:06 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2011-08-24 21:39:38 +00:00
|
|
|
# remotinator - send commands to Terminator via DBus
|
|
|
|
# Copyright (C) 2006-2010 cmsj@tenshu.net
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 2 only.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2021-01-12 17:35:10 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
2011-08-24 21:39:38 +00:00
|
|
|
# USA
|
|
|
|
|
|
|
|
"""remotinator by Chris Jones <cmsj@tenshu.net>"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2015-09-19 03:25:25 +00:00
|
|
|
import argparse
|
2011-08-24 21:39:38 +00:00
|
|
|
|
|
|
|
from terminatorlib.util import dbg, err
|
2016-11-23 04:53:27 +00:00
|
|
|
from terminatorlib.version import APP_VERSION
|
2011-09-28 11:50:19 +00:00
|
|
|
try:
|
|
|
|
from terminatorlib import ipc
|
2012-10-18 20:58:38 +00:00
|
|
|
except ImportError:
|
2011-09-28 11:50:19 +00:00
|
|
|
err('Unable to initialise Terminator remote library. This probably means dbus is not available')
|
|
|
|
sys.exit(1)
|
2015-09-19 03:25:25 +00:00
|
|
|
from terminatorlib.translation import _
|
2011-08-24 21:39:38 +00:00
|
|
|
|
|
|
|
APP_NAME='remotinator'
|
|
|
|
|
|
|
|
COMMANDS={
|
2021-02-19 03:44:53 +00:00
|
|
|
# Command uuid req. Description
|
|
|
|
'new_window': [False, _('Open a new window')],
|
|
|
|
'new_tab': [True, _('Open a new tab')],
|
|
|
|
'hsplit': [True, _('Split the current terminal horizontally')],
|
|
|
|
'vsplit': [True, _('Split the current terminal vertically')],
|
|
|
|
'get_terminals': [False, _('Get a list of all terminals')],
|
|
|
|
'get_focused_terminal': [False, _('Get the uuid of the current focused terminal')],
|
|
|
|
'get_window': [True, _('Get the UUID of a parent window')],
|
|
|
|
'get_window_title': [True, _('Get the title of a parent window')],
|
|
|
|
'get_tab': [True, _('Get the UUID of a parent tab')],
|
|
|
|
'get_tab_title': [True, _('Get the title of a parent tab')],
|
2021-05-07 23:51:06 +00:00
|
|
|
'set_tab_title': [True, _('Set the title of a parent tab')],
|
|
|
|
'switch_profile': [True, _('Switch current terminal profile')],
|
2015-09-19 03:25:25 +00:00
|
|
|
}
|
2011-08-24 21:39:38 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))
|
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
command_desc=''
|
|
|
|
for command in sorted(COMMANDS.keys()):
|
|
|
|
command_desc += " %-*s %s %s\n" % (max([len(x) for x in COMMANDS.keys()]),
|
|
|
|
command,
|
|
|
|
COMMANDS[command][0] and '*' or ' ',
|
|
|
|
COMMANDS[command][1])
|
2011-08-24 21:39:38 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
# Parse args
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
2021-01-12 17:35:10 +00:00
|
|
|
usage='%(prog)s command [options]',
|
|
|
|
description=_('Run one of the following Terminator DBus commands:\n\n%s') % (command_desc),
|
2015-09-19 03:25:25 +00:00
|
|
|
epilog=_('* These entries require either TERMINATOR_UUID environment var,\n or the --uuid option must be used.'))
|
2021-01-12 17:35:10 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
parser.add_argument('command', type=str, nargs=1, choices=sorted(COMMANDS.keys()),
|
|
|
|
help=argparse.SUPPRESS)
|
2021-01-12 17:35:10 +00:00
|
|
|
|
|
|
|
parser.add_argument('-u', '--uuid', dest='uuid', type=str, metavar='UUID', default=argparse.SUPPRESS,
|
|
|
|
help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
|
|
|
|
|
|
|
|
parser.add_argument('-p', '--profile', dest='profile', type=str, default=argparse.SUPPRESS,
|
|
|
|
help=_('Terminal UUID for when not in env var TERMINATOR_UUID'))
|
|
|
|
|
2021-05-07 23:51:06 +00:00
|
|
|
parser.add_argument('-t', '--tab-title', dest='tab-title', type=str, default="Missing Tab Title! Use -t argument!",
|
|
|
|
help=_('Tab name to set. Only used with "set_tab_title" command.'))
|
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
parser.add_argument('-v', '--version', action='version', version='%%(prog)s %s' %(APP_VERSION))
|
2021-01-12 17:35:10 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
options = vars(parser.parse_args()) # Straight to dict
|
2011-08-24 21:39:38 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
# Pull out the command
|
|
|
|
command = options['command'][0]
|
|
|
|
del options['command']
|
2011-08-25 21:10:04 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
func = getattr(ipc, command)
|
|
|
|
uuid_required = COMMANDS[command][0]
|
2021-01-12 17:35:10 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
if uuid_required:
|
|
|
|
uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID'))
|
|
|
|
if uuid:
|
2021-02-19 03:44:53 +00:00
|
|
|
print(str(func(uuid, options)))
|
2015-09-19 03:25:25 +00:00
|
|
|
else:
|
|
|
|
err("$TERMINATOR_UUID is not set, or passed as an option.")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2021-02-19 03:44:53 +00:00
|
|
|
print(str(func(options)))
|