Merge pull request #506 from Vulcalien/master

Improve argument parser + implement bash completion
This commit is contained in:
Matt Rose 2021-12-19 13:21:46 -05:00 committed by GitHub
commit d2c428bc60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
85 changed files with 23311 additions and 17750 deletions

16
completion/bash Normal file
View File

@ -0,0 +1,16 @@
# bash completion for terminator -*- shell-script -*-
_terminator()
{
local cur prev words cword
_init_completion || return
# TODO implement completion for --profile and --layout
COMPREPLY=($(compgen -W "$($1 --help | tr ',' '\n' |
command sed -n -e 's/^ *\(--\?[a-zA-Z\-]\+=\?\).*/\1/p')"\
-- "$cur"))
} &&
complete -F _terminator terminator
# ex: filetype=sh

491
po/af.po

File diff suppressed because it is too large Load Diff

501
po/ar.po

File diff suppressed because it is too large Load Diff

491
po/ast.po

File diff suppressed because it is too large Load Diff

483
po/az.po

File diff suppressed because it is too large Load Diff

483
po/be.po

File diff suppressed because it is too large Load Diff

493
po/bg.po

File diff suppressed because it is too large Load Diff

487
po/bn.po

File diff suppressed because it is too large Load Diff

507
po/bs.po

File diff suppressed because it is too large Load Diff

501
po/ca.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

483
po/ckb.po

File diff suppressed because it is too large Load Diff

507
po/cs.po

File diff suppressed because it is too large Load Diff

502
po/da.po

File diff suppressed because it is too large Load Diff

507
po/de.po

File diff suppressed because it is too large Load Diff

507
po/el.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

493
po/eo.po

File diff suppressed because it is too large Load Diff

507
po/es.po

File diff suppressed because it is too large Load Diff

487
po/et.po

File diff suppressed because it is too large Load Diff

501
po/eu.po

File diff suppressed because it is too large Load Diff

487
po/fa.po

File diff suppressed because it is too large Load Diff

491
po/fi.po

File diff suppressed because it is too large Load Diff

483
po/fo.po

File diff suppressed because it is too large Load Diff

507
po/fr.po

File diff suppressed because it is too large Load Diff

483
po/fy.po

File diff suppressed because it is too large Load Diff

483
po/ga.po

File diff suppressed because it is too large Load Diff

491
po/gl.po

File diff suppressed because it is too large Load Diff

507
po/he.po

File diff suppressed because it is too large Load Diff

487
po/hi.po

File diff suppressed because it is too large Load Diff

507
po/hr.po

File diff suppressed because it is too large Load Diff

493
po/hu.po

File diff suppressed because it is too large Load Diff

483
po/hy.po

File diff suppressed because it is too large Load Diff

486
po/ia.po

File diff suppressed because it is too large Load Diff

507
po/id.po

File diff suppressed because it is too large Load Diff

487
po/is.po

File diff suppressed because it is too large Load Diff

499
po/it.po

File diff suppressed because it is too large Load Diff

512
po/ja.po

File diff suppressed because it is too large Load Diff

483
po/jv.po

File diff suppressed because it is too large Load Diff

483
po/ka.po

File diff suppressed because it is too large Load Diff

491
po/kk.po

File diff suppressed because it is too large Load Diff

507
po/ko.po

File diff suppressed because it is too large Load Diff

486
po/ku.po

File diff suppressed because it is too large Load Diff

483
po/la.po

File diff suppressed because it is too large Load Diff

491
po/lt.po

File diff suppressed because it is too large Load Diff

491
po/lv.po

File diff suppressed because it is too large Load Diff

487
po/mk.po

File diff suppressed because it is too large Load Diff

483
po/ml.po

File diff suppressed because it is too large Load Diff

483
po/mr.po

File diff suppressed because it is too large Load Diff

502
po/ms.po

File diff suppressed because it is too large Load Diff

501
po/nb.po

File diff suppressed because it is too large Load Diff

507
po/nl.po

File diff suppressed because it is too large Load Diff

483
po/nn.po

File diff suppressed because it is too large Load Diff

487
po/oc.po

File diff suppressed because it is too large Load Diff

510
po/pl.po

File diff suppressed because it is too large Load Diff

507
po/pt.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

491
po/ro.po

File diff suppressed because it is too large Load Diff

507
po/ru.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

483
po/si.po

File diff suppressed because it is too large Load Diff

502
po/sk.po

File diff suppressed because it is too large Load Diff

487
po/sl.po

File diff suppressed because it is too large Load Diff

483
po/sq.po

File diff suppressed because it is too large Load Diff

491
po/sr.po

File diff suppressed because it is too large Load Diff

483
po/su.po

File diff suppressed because it is too large Load Diff

508
po/sv.po

File diff suppressed because it is too large Load Diff

483
po/sw.po

File diff suppressed because it is too large Load Diff

491
po/ta.po

File diff suppressed because it is too large Load Diff

483
po/te.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

483
po/th.po

File diff suppressed because it is too large Load Diff

510
po/tr.po

File diff suppressed because it is too large Load Diff

483
po/tyv.po

File diff suppressed because it is too large Load Diff

483
po/ug.po

File diff suppressed because it is too large Load Diff

507
po/uk.po

File diff suppressed because it is too large Load Diff

483
po/ur.po

File diff suppressed because it is too large Load Diff

483
po/vi.po

File diff suppressed because it is too large Load Diff

483
po/wa.po

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,10 +15,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Terminator.optionparse - Parse commandline options"""
import argparse
import sys
import os
from optparse import OptionParser, SUPPRESS_HELP
from terminatorlib.terminator import Terminator
from .util import dbg, err
from . import util
from . import config
@ -27,98 +28,100 @@ from .translation import _
options = None
def execute_cb(option, opt, value, lparser):
"""Callback for use in parsing execute options"""
assert value is None
value = []
while lparser.rargs:
arg = lparser.rargs[0]
value.append(arg)
del(lparser.rargs[0])
setattr(lparser.values, option.dest, value)
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)
def parse_options():
"""Parse the command line options"""
usage = "usage: %prog [options]"
is_x_terminal_emulator = os.path.basename(sys.argv[0]) == 'x-terminal-emulator'
parser = OptionParser(usage)
parser = argparse.ArgumentParser()
parser.add_option('-v', '--version', action='store_true', dest='version',
parser.add_argument('-v', '--version', action='store_true', dest='version',
help=_('Display program version'))
parser.add_option('-m', '--maximise', action='store_true', dest='maximise',
parser.add_argument('-m', '--maximise', action='store_true', dest='maximise',
help=_('Maximize the window'))
parser.add_option('-M', '--maximize', action='store_true', dest='maximise',
parser.add_argument('-M', '--maximize', action='store_true', dest='maximise',
help=_('Maximize the window'))
parser.add_option('-f', '--fullscreen', action='store_true',
parser.add_argument('-f', '--fullscreen', action='store_true',
dest='fullscreen', help=_('Make the window fill the screen'))
parser.add_option('-b', '--borderless', action='store_true',
parser.add_argument('-b', '--borderless', action='store_true',
dest='borderless', help=_('Disable window borders'))
parser.add_option('-H', '--hidden', action='store_true', dest='hidden',
parser.add_argument('-H', '--hidden', action='store_true', dest='hidden',
help=_('Hide the window at startup'))
parser.add_option('-T', '--title', dest='forcedtitle',
parser.add_argument('-T', '--title', dest='forcedtitle',
help=_('Specify a title for the window'))
parser.add_option('--geometry', dest='geometry', type='string',
parser.add_argument('--geometry', dest='geometry', type=str,
help=_('Set the preferred size and position of the window'
'(see X man page)'))
if not is_x_terminal_emulator:
parser.add_option('-e', '--command', dest='command',
parser.add_argument('-e', '--command', dest='command',
help=_('Specify a command to execute inside the terminal'))
else:
parser.add_option('--command', dest='command',
parser.add_argument('--command', dest='command',
help=_('Specify a command to execute inside the terminal'))
parser.add_option('-e', '--execute2', dest='execute', action='callback',
callback=execute_cb,
parser.add_argument('-e', '--execute2', dest='execute', action=ExecuteCallback,
help=_('Use the rest of the command line as a command to '
'execute inside the terminal, and its arguments'))
parser.add_option('-g', '--config', dest='config',
parser.add_argument('-g', '--config', dest='config',
help=_('Specify a config file'))
parser.add_option('-j', '--config-json', dest='configjson',
parser.add_argument('-j', '--config-json', dest='configjson',
help=_('Specify a partial config json file'))
parser.add_option('-x', '--execute', dest='execute', action='callback',
callback=execute_cb,
parser.add_argument('-x', '--execute', dest='execute', action=ExecuteCallback,
help=_('Use the rest of the command line as a command to execute '
'inside the terminal, and its arguments'))
parser.add_option('--working-directory', metavar='DIR',
parser.add_argument('--working-directory', metavar='DIR',
dest='working_directory', help=_('Set the working directory'))
parser.add_option('-i', '--icon', dest='forcedicon', help=_('Set a custom \
parser.add_argument('-i', '--icon', dest='forcedicon', help=_('Set a custom \
icon for the window (by file or name)'))
parser.add_option('-r', '--role', dest='role',
parser.add_argument('-r', '--role', dest='role',
help=_('Set a custom WM_WINDOW_ROLE property on the window'))
parser.add_option('-l', '--layout', dest='layout',
parser.add_argument('-l', '--layout', dest='layout',
help=_('Launch with the given layout'))
parser.add_option('-s', '--select-layout', action='store_true',
parser.add_argument('-s', '--select-layout', action='store_true',
dest='select', help=_('Select a layout from a list'))
parser.add_option('-p', '--profile', dest='profile',
parser.add_argument('-p', '--profile', dest='profile',
help=_('Use a different profile as the default'))
parser.add_option('-u', '--no-dbus', action='store_true', dest='nodbus',
parser.add_argument('-u', '--no-dbus', action='store_true', dest='nodbus',
help=_('Disable DBus'))
parser.add_option('-d', '--debug', action='count', dest='debug',
parser.add_argument('-d', '--debug', action='count', dest='debug',
help=_('Enable debugging information (twice for debug server)'))
parser.add_option('--debug-classes', action='store', dest='debug_classes',
parser.add_argument('--debug-classes', action='store', dest='debug_classes',
help=_('Comma separated list of classes to limit debugging to'))
parser.add_option('--debug-methods', action='store', dest='debug_methods',
parser.add_argument('--debug-methods', action='store', dest='debug_methods',
help=_('Comma separated list of methods to limit debugging to'))
parser.add_option('--new-tab', action='store_true', dest='new_tab',
parser.add_argument('--new-tab', action='store_true', dest='new_tab',
help=_('If Terminator is already running, just open a new tab'))
parser.add_option('--unhide', action='store_true', dest='unhide',
parser.add_argument('--unhide', action='store_true', dest='unhide',
help=_('If Terminator is already running, just unhide all hidden windows'))
parser.add_argument('--list-profiles', action='store_true', dest='list_profiles',
help=_('List all profiles'))
parser.add_argument('--list-layouts', action='store_true', dest='list_layouts',
help=_('List all layouts'))
for item in ['--sm-client-id', '--sm-config-prefix', '--screen', '-n',
'--no-gconf' ]:
parser.add_option(item, dest='dummy', action='store',
help=SUPPRESS_HELP)
parser.add_argument(item, dest='dummy', action='store',
help=argparse.SUPPRESS)
global options
(options, args) = parser.parse_args()
if len(args) != 0:
parser.error('Additional unexpected arguments found: %s' % args)
options = parser.parse_args()
if options.version:
print('%s %s' % (version.APP_NAME, version.APP_VERSION))
sys.exit(0)
if options.list_profiles:
for p in Terminator().config.list_profiles():
print(p)
sys.exit(0)
if options.list_layouts:
for l in Terminator().config.list_layouts():
print(l)
sys.exit(0)
if options.debug_classes or options.debug_methods:
if not options.debug > 0:
options.debug = 1
@ -165,5 +168,4 @@ icon for the window (by file or name)'))
if util.DEBUG == True:
dbg('OptionParse::parse_options: command line options: %s' % options)
return(options,optionslist)