Example #1
0
def complete_kitty_cli_arg(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None:
    prefix = prefix or ''
    if not opt:
        if unknown_args.num_of_unknown_args > 0:
            ans.delegate = unknown_args
        return
    dest = opt['dest']
    if dest == 'override':
        from kitty.config import option_names_for_completion
        k = 'Config directives'
        ans.add_match_group(k, {k+'=': '' for k in option_names_for_completion() if k.startswith(prefix)}, trailing_space=False)
    elif dest == 'config':

        def is_conf_file(x: str) -> bool:
            if os.path.isdir(x):
                return True
            return x.lower().endswith('.conf')

        complete_files_and_dirs(ans, prefix, files_group_name='Config files', predicate=is_conf_file)
    elif dest == 'session':
        complete_files_and_dirs(ans, prefix, files_group_name='Session files')
    elif dest == 'watcher':
        complete_files_and_dirs(ans, prefix, files_group_name='Watcher files')
    elif dest == 'directory':
        complete_files_and_dirs(ans, prefix, files_group_name='Directories', predicate=os.path.isdir)
    elif dest == 'start_as':
        k = 'Start as'
        ans.add_match_group(k, {x: x for x in 'normal,fullscreen,maximized,minimized'.split(',') if x.startswith(prefix)}, trailing_space=False)
    elif dest == 'listen_on':
        if ':' not in prefix:
            k = 'Address type'
            ans.add_match_group(k, {x: x for x in ('unix:', 'tcp:') if x.startswith(prefix)}, trailing_space=False)
        elif prefix.startswith('unix:') and not prefix.startswith('@'):
            complete_files_and_dirs(ans, prefix[len('unix:'):], files_group_name='UNIX sockets', add_prefix='unix:')
Example #2
0
def complete_kitty_cli_arg(ans, opt, prefix):
    prefix = prefix or ''
    if opt and opt['dest'] == 'override':
        from kitty.config import option_names_for_completion
        k = 'Config directives'
        ans.match_groups[k] = {
            k + '=': None
            for k in option_names_for_completion() if k.startswith(prefix)
        }
        ans.no_space_groups.add(k)
Example #3
0
def complete_kitty_cli_arg(ans, opt, prefix):
    prefix = prefix or ''
    if not opt:
        return
    dest = opt['dest']
    if dest == 'override':
        from kitty.config import option_names_for_completion
        k = 'Config directives'
        ans.match_groups[k] = {
            k + '=': None
            for k in option_names_for_completion() if k.startswith(prefix)
        }
        ans.no_space_groups.add(k)
    elif dest == 'config':

        def is_conf_file(x):
            if os.path.isdir(x):
                return True
            return x.lower().endswith('.conf')

        complete_files_and_dirs(ans,
                                prefix,
                                files_group_name='Config files',
                                predicate=is_conf_file)
    elif dest == 'session':
        complete_files_and_dirs(ans, prefix, files_group_name='Session files')
    elif dest == 'directory':
        complete_files_and_dirs(ans,
                                prefix,
                                files_group_name='Directories',
                                predicate=os.path.isdir)
    elif dest == 'start_as':
        k = 'Start as'
        ans.match_groups[k] = {
            x: x
            for x in 'normal,fullscreen,maximized,minimized'.split(',')
            if x.startswith(prefix)
        }
        ans.no_space_groups.add(k)
    elif dest == 'listen_on':
        if ':' not in prefix:
            k = 'Address type'
            ans.match_groups[k] = {
                x: x
                for x in ('unix:', 'tcp:') if x.startswith(prefix)
            }
            ans.no_space_groups.add(k)
        elif prefix.startswith('unix:') and not prefix.startswith('@'):
            complete_files_and_dirs(ans,
                                    prefix[len('unix:'):],
                                    files_group_name='UNIX sockets',
                                    add_prefix='unix:')