File tree 2 files changed +53
-2
lines changed
2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 13
13
import libtmux
14
14
from libtmux .common import has_lt_version
15
15
from 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
+ )
17
23
18
24
from .fixtures ._util import curjoin , loadfixture
19
25
@@ -574,3 +580,33 @@ def check_cmd(config_arg):
574
580
assert str (user_config ) in check_cmd (str (configdir .join ('myconfig.yaml' )))
575
581
576
582
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 26
26
27
27
logger = logging .getLogger (__name__ )
28
28
29
+ VALID_CONFIG_DIR_FILE_EXTENSIONS = ['.yaml' , '.yml' , '.json' ]
30
+
29
31
30
32
def get_cwd ():
31
33
return os .getcwd ()
@@ -326,7 +328,7 @@ def scan_config(config, config_dir=None):
326
328
x
327
329
for x in [
328
330
'%s%s' % (join (config_dir , config ), ext )
329
- for ext in [ '.yaml' , '.yml' , '.json' ]
331
+ for ext in VALID_CONFIG_DIR_FILE_EXTENSIONS
330
332
]
331
333
if exists (x )
332
334
]
@@ -924,3 +926,16 @@ def command_convert(config):
924
926
buf .write (newconfig )
925
927
buf .close ()
926
928
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