2020-04-05 14:36:06 +00:00
|
|
|
# Terminator.optionparse - Parse commandline options
|
|
|
|
# Copyright (C) 2006-2010 cmsj@tenshu.net
|
2010-01-04 23:52:39 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
"""Terminator.optionparse - Parse commandline options"""
|
|
|
|
|
2021-09-09 14:05:39 +00:00
|
|
|
import argparse
|
2010-01-04 23:52:39 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2021-09-09 09:48:19 +00:00
|
|
|
from terminatorlib.terminator import Terminator
|
2018-04-24 18:22:10 +00:00
|
|
|
from .util import dbg, err
|
|
|
|
from . import util
|
|
|
|
from . import config
|
|
|
|
from . import version
|
|
|
|
from .translation import _
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
options = None
|
|
|
|
|
2021-09-09 14:05:39 +00:00
|
|
|
class ExecuteCallback(argparse.Action):
|
|
|
|
def __call__(self, lparser, namespace, values, option_string=None):
|
|
|
|
"""Callback for use in parsing execute options"""
|
|
|
|
setattr(namespace, self.dest, values)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
|
|
|
def parse_options():
|
|
|
|
"""Parse the command line options"""
|
2013-08-27 11:37:09 +00:00
|
|
|
is_x_terminal_emulator = os.path.basename(sys.argv[0]) == 'x-terminal-emulator'
|
2013-05-13 04:44:07 +00:00
|
|
|
|
2021-09-09 14:05:39 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2022-10-24 05:51:53 +00:00
|
|
|
parser.add_argument('-R', '--reload', action='store_true', dest='reload',
|
|
|
|
help=_('Reload terminator configuration'))
|
|
|
|
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-v', '--version', action='store_true', dest='version',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Display program version'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-m', '--maximise', action='store_true', dest='maximise',
|
2015-11-28 23:39:22 +00:00
|
|
|
help=_('Maximize the window'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-M', '--maximize', action='store_true', dest='maximise',
|
2020-06-11 18:01:15 +00:00
|
|
|
help=_('Maximize the window'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-f', '--fullscreen', action='store_true',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='fullscreen', help=_('Make the window fill the screen'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-b', '--borderless', action='store_true',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='borderless', help=_('Disable window borders'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-H', '--hidden', action='store_true', dest='hidden',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Hide the window at startup'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-T', '--title', dest='forcedtitle',
|
2011-12-29 20:39:09 +00:00
|
|
|
help=_('Specify a title for the window'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--geometry', dest='geometry', type=str,
|
2011-12-29 20:39:09 +00:00
|
|
|
help=_('Set the preferred size and position of the window'
|
|
|
|
'(see X man page)'))
|
2013-08-27 11:37:09 +00:00
|
|
|
if not is_x_terminal_emulator:
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-e', '--command', dest='command',
|
2013-08-04 19:36:33 +00:00
|
|
|
help=_('Specify a command to execute inside the terminal'))
|
2013-08-27 11:37:09 +00:00
|
|
|
else:
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--command', dest='command',
|
2013-08-04 19:36:33 +00:00
|
|
|
help=_('Specify a command to execute inside the terminal'))
|
2022-11-18 13:12:59 +00:00
|
|
|
parser.add_argument('-e', '--execute2', dest='execute',
|
|
|
|
nargs=argparse.REMAINDER, action=ExecuteCallback,
|
2013-08-27 11:37:09 +00:00
|
|
|
help=_('Use the rest of the command line as a command to '
|
2013-08-04 19:36:33 +00:00
|
|
|
'execute inside the terminal, and its arguments'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-g', '--config', dest='config',
|
2012-10-19 05:14:39 +00:00
|
|
|
help=_('Specify a config file'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-j', '--config-json', dest='configjson',
|
2020-09-20 20:54:10 +00:00
|
|
|
help=_('Specify a partial config json file'))
|
2022-11-18 13:12:59 +00:00
|
|
|
parser.add_argument('-x', '--execute', dest='execute',
|
|
|
|
nargs=argparse.REMAINDER, action=ExecuteCallback,
|
2013-01-30 13:17:11 +00:00
|
|
|
help=_('Use the rest of the command line as a command to execute '
|
|
|
|
'inside the terminal, and its arguments'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--working-directory', metavar='DIR',
|
2010-09-04 09:03:57 +00:00
|
|
|
dest='working_directory', help=_('Set the working directory'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-i', '--icon', dest='forcedicon', help=_('Set a custom \
|
2012-06-28 16:07:00 +00:00
|
|
|
icon for the window (by file or name)'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-r', '--role', dest='role',
|
2011-12-29 20:39:09 +00:00
|
|
|
help=_('Set a custom WM_WINDOW_ROLE property on the window'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-l', '--layout', dest='layout',
|
2013-08-28 21:09:17 +00:00
|
|
|
help=_('Launch with the given layout'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-s', '--select-layout', action='store_true',
|
2013-08-28 21:09:17 +00:00
|
|
|
dest='select', help=_('Select a layout from a list'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-p', '--profile', dest='profile',
|
2011-12-29 20:39:09 +00:00
|
|
|
help=_('Use a different profile as the default'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-u', '--no-dbus', action='store_true', dest='nodbus',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Disable DBus'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('-d', '--debug', action='count', dest='debug',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Enable debugging information (twice for debug server)'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--debug-classes', action='store', dest='debug_classes',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Comma separated list of classes to limit debugging to'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--debug-methods', action='store', dest='debug_methods',
|
2010-09-04 09:03:57 +00:00
|
|
|
help=_('Comma separated list of methods to limit debugging to'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--new-tab', action='store_true', dest='new_tab',
|
2012-10-30 00:11:24 +00:00
|
|
|
help=_('If Terminator is already running, just open a new tab'))
|
2023-07-20 15:08:44 +00:00
|
|
|
parser.add_argument('--toggle-visibility', action='store_true', dest='toggle_visibility',
|
|
|
|
help=_('If Terminator is already running, toggle windows visibility'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--unhide', action='store_true', dest='unhide',
|
2020-11-26 20:35:12 +00:00
|
|
|
help=_('If Terminator is already running, just unhide all hidden windows'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--list-profiles', action='store_true', dest='list_profiles',
|
2021-09-09 09:48:19 +00:00
|
|
|
help=_('List all profiles'))
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument('--list-layouts', action='store_true', dest='list_layouts',
|
2021-09-09 09:48:19 +00:00
|
|
|
help=_('List all layouts'))
|
2020-11-26 20:35:12 +00:00
|
|
|
|
2010-01-05 12:51:53 +00:00
|
|
|
for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n',
|
2011-12-29 20:39:09 +00:00
|
|
|
'--no-gconf' ]:
|
2021-09-09 14:05:39 +00:00
|
|
|
parser.add_argument(item, dest='dummy', action='store',
|
|
|
|
help=argparse.SUPPRESS)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
global options
|
2021-09-09 14:05:39 +00:00
|
|
|
options = parser.parse_args()
|
2010-01-04 23:52:39 +00:00
|
|
|
|
|
|
|
if options.version:
|
2018-04-24 18:22:10 +00:00
|
|
|
print('%s %s' % (version.APP_NAME, version.APP_VERSION))
|
2010-01-04 23:52:39 +00:00
|
|
|
sys.exit(0)
|
2010-02-17 20:16:52 +00:00
|
|
|
|
2021-09-09 09:48:19 +00:00
|
|
|
if options.list_profiles:
|
2021-10-11 10:04:47 +00:00
|
|
|
for p in Terminator().config.list_profiles():
|
|
|
|
print(p)
|
2021-09-09 09:48:19 +00:00
|
|
|
sys.exit(0)
|
|
|
|
if options.list_layouts:
|
2021-10-11 10:04:47 +00:00
|
|
|
for l in Terminator().config.list_layouts():
|
|
|
|
print(l)
|
2021-09-09 09:48:19 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2010-02-17 20:16:52 +00:00
|
|
|
if options.debug_classes or options.debug_methods:
|
2010-03-21 00:48:39 +00:00
|
|
|
if not options.debug > 0:
|
2010-03-21 00:49:22 +00:00
|
|
|
options.debug = 1
|
2010-02-17 20:16:52 +00:00
|
|
|
|
2010-01-04 23:52:39 +00:00
|
|
|
if options.debug:
|
|
|
|
util.DEBUG = True
|
2010-01-22 19:04:37 +00:00
|
|
|
if options.debug > 1:
|
2010-01-14 13:15:05 +00:00
|
|
|
util.DEBUGFILES = True
|
2010-02-17 20:16:52 +00:00
|
|
|
if options.debug_classes:
|
|
|
|
classes = options.debug_classes.split(',')
|
|
|
|
for item in classes:
|
|
|
|
util.DEBUGCLASSES.append(item.strip())
|
|
|
|
if options.debug_methods:
|
|
|
|
methods = options.debug_methods.split(',')
|
|
|
|
for item in methods:
|
|
|
|
util.DEBUGMETHODS.append(item.strip())
|
2010-01-04 23:52:39 +00:00
|
|
|
|
|
|
|
if options.working_directory:
|
|
|
|
if os.path.exists(os.path.expanduser(options.working_directory)):
|
2016-12-02 21:45:49 +00:00
|
|
|
options.working_directory = os.path.expanduser(options.working_directory)
|
|
|
|
os.chdir(options.working_directory)
|
2010-01-04 23:52:39 +00:00
|
|
|
else:
|
|
|
|
err('OptionParse::parse_options: %s does not exist' %
|
|
|
|
options.working_directory)
|
2010-03-31 13:02:55 +00:00
|
|
|
options.working_directory = ''
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2010-02-04 23:52:43 +00:00
|
|
|
if options.layout is None:
|
|
|
|
options.layout = 'default'
|
|
|
|
|
2012-03-30 19:35:19 +00:00
|
|
|
configobj = config.Config()
|
2010-05-15 13:51:20 +00:00
|
|
|
if options.profile and options.profile not in configobj.list_profiles():
|
|
|
|
options.profile = None
|
|
|
|
|
2010-01-11 20:56:30 +00:00
|
|
|
configobj.options_set(options)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2020-08-28 20:51:37 +00:00
|
|
|
optionslist = {}
|
|
|
|
for opt, val in list(options.__dict__.items()):
|
|
|
|
if type(val) == type([]):
|
|
|
|
val = ' '.join(val)
|
|
|
|
if val == True:
|
|
|
|
val = 'True'
|
|
|
|
optionslist[opt] = val and '%s'%val or ''
|
|
|
|
# optionslist = dbus.Dictionary(optionslist, signature='ss')
|
2010-01-04 23:52:39 +00:00
|
|
|
if util.DEBUG == True:
|
2022-01-28 20:51:54 +00:00
|
|
|
dbg('command line options: %s' % options)
|
2010-01-04 23:52:39 +00:00
|
|
|
|
2020-08-28 20:51:37 +00:00
|
|
|
return(options,optionslist)
|