File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 1313import libtmux
1414from libtmux .common import has_lt_version
1515from tmuxp import cli , config
16- from tmuxp .cli import get_config_dir , is_pure_name , load_workspace , scan_config
16+ from tmuxp .cli import (
17+ command_ls ,
18+ get_config_dir ,
19+ is_pure_name ,
20+ load_workspace ,
21+ scan_config ,
22+ )
1723
1824from .fixtures ._util import curjoin , loadfixture
1925
@@ -574,3 +580,33 @@ def check_cmd(config_arg):
574580 assert str (user_config ) in check_cmd (str (configdir .join ('myconfig.yaml' )))
575581
576582 assert 'file not found' in check_cmd ('.tmuxp.json' )
583+
584+
585+ def test_ls_cli (monkeypatch , tmpdir ):
586+ monkeypatch .setenv ("HOME" , str (tmpdir ))
587+
588+ filenames = [
589+ '.git/' ,
590+ '.gitignore/' ,
591+ 'session_1.yaml' ,
592+ 'session_2.yaml' ,
593+ 'session_3.json' ,
594+ 'session_4.txt' ,
595+ ]
596+
597+ # should ignore:
598+ # - directories should be ignored
599+ # - extensions not covered in VALID_CONFIG_DIR_FILE_EXTENSIONS
600+ ignored_filenames = ['.git/' , '.gitignore/' , 'session_4.txt' ]
601+ stems = [os .path .splitext (f )[0 ] for f in filenames if f not in ignored_filenames ]
602+
603+ for filename in filenames :
604+ location = tmpdir .join ('.tmuxp/{}' .format (filename ))
605+ if filename .endswith ('/' ):
606+ location .ensure_dir ()
607+ else :
608+ location .ensure ()
609+
610+ runner = CliRunner ()
611+ cli_output = runner .invoke (command_ls ).output
612+ assert cli_output == '\n ' .join (stems ) + '\n '
Original file line number Diff line number Diff line change 2626
2727logger = logging .getLogger (__name__ )
2828
29+ VALID_CONFIG_DIR_FILE_EXTENSIONS = ['.yaml' , '.yml' , '.json' ]
30+
2931
3032def get_cwd ():
3133 return os .getcwd ()
@@ -326,7 +328,7 @@ def scan_config(config, config_dir=None):
326328 x
327329 for x in [
328330 '%s%s' % (join (config_dir , config ), ext )
329- for ext in [ '.yaml' , '.yml' , '.json' ]
331+ for ext in VALID_CONFIG_DIR_FILE_EXTENSIONS
330332 ]
331333 if exists (x )
332334 ]
@@ -924,3 +926,16 @@ def command_convert(config):
924926 buf .write (newconfig )
925927 buf .close ()
926928 print ('New config saved to <%s>.' % newfile )
929+
930+
931+ @cli .command (
932+ name = 'ls' , short_help = 'List configured sessions in {}.' .format (get_config_dir ())
933+ )
934+ def command_ls ():
935+ tmuxp_dir = get_config_dir ()
936+ if os .path .exists (tmuxp_dir ) and os .path .isdir (tmuxp_dir ):
937+ for f in sorted (os .listdir (tmuxp_dir )):
938+ stem , ext = os .path .splitext (f )
939+ if os .path .isdir (f ) or ext not in VALID_CONFIG_DIR_FILE_EXTENSIONS :
940+ continue
941+ print (stem )
You can’t perform that action at this time.
0 commit comments