2011-08-24 21:39:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# 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
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
# 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
|
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'
|
2016-11-03 03:03:51 +00:00
|
|
|
APP_VERSION='1.90'
|
2011-08-24 21:39:38 +00:00
|
|
|
|
|
|
|
COMMANDS={
|
2015-09-19 03:25:25 +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_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')],
|
|
|
|
}
|
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,
|
|
|
|
usage='%(prog)s command [options]',
|
|
|
|
description=_('Run one of the following Terminator DBus commands:\n\n%s') % (command_desc),
|
|
|
|
epilog=_('* These entries require either TERMINATOR_UUID environment var,\n or the --uuid option must be used.'))
|
|
|
|
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('command', type=str, nargs=1, choices=sorted(COMMANDS.keys()),
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
parser.add_argument('-v', '--version', action='version', version='%%(prog)s %s' %(APP_VERSION))
|
|
|
|
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)
|
2011-08-24 21:39:38 +00:00
|
|
|
|
2015-09-19 03:25:25 +00:00
|
|
|
uuid_required = COMMANDS[command][0]
|
|
|
|
if uuid_required:
|
|
|
|
uuid = options.get('uuid', os.environ.get('TERMINATOR_UUID'))
|
|
|
|
if uuid:
|
|
|
|
func(uuid, options)
|
|
|
|
else:
|
|
|
|
err("$TERMINATOR_UUID is not set, or passed as an option.")
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
func(options)
|