diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 82843b3acee..5951f70ae9c 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -7,6 +7,7 @@ """ from __future__ import absolute_import +import glob import logging import os import sys @@ -922,3 +923,29 @@ def command_convert(config): buf.write(newconfig) buf.close() print('New config saved to <%s>.' % newfile) + + +@cli.command(name='list') +@click.argument('config_dir', type=click.Path(exists=True), nargs=1, + required=False) +def command_list(config_dir=None): + """List existing workspace configurations. + + CONFIG_DIR is an optional argument, if it's a valid directory path + then workspace configurations will be looked there. + """ + + if not config_dir: + config_dir = get_config_dir() + join = os.path.join + + tails = ('*.yml', '*.yaml', '*.json') + config_files = sum((glob.glob(join(config_dir, tail)) for tail in tails), + []) + + if config_files: + click.echo("Configuration files found in '%s':" % config_dir) + for config_file in config_files: + config_file = config_file.replace(config_dir, '') + config_file = ''.join(config_file.split('.')[:-1]) + click.echo(" %s" % config_file)