Skip to content

Add command to list layouts in config directory #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from __future__ import absolute_import

import glob
import logging
import os
import sys
Expand Down Expand Up @@ -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)