22
22
23
23
24
24
import re
25
- VERSIONFILE = os .path .join (os .path .abspath (os .path .dirname (__file__ )), '__init__.py' )
25
+ VERSIONFILE = os .path .join (
26
+ os .path .abspath (os .path .dirname (__file__ )), '__init__.py'
27
+ )
26
28
verstrline = open (VERSIONFILE , "rt" ).read ()
27
29
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
28
30
mo = re .search (VSRE , verstrline , re .M )
29
31
if mo :
30
32
__version__ = mo .group (1 )
31
- #import pkg_resources
32
- #__version__ = pkg_resources.require("tmuxp")[0].version
33
33
34
34
logger = logging .getLogger (__name__ )
35
35
@@ -277,7 +277,9 @@ def load_workspace(config_file, args):
277
277
builder .build ()
278
278
279
279
if 'TMUX' in os .environ :
280
- if args .answer_yes or prompt_yes_no ('Already inside TMUX, switch to session?' ):
280
+ if args .answer_yes or prompt_yes_no (
281
+ 'Already inside TMUX, switch to session?'
282
+ ):
281
283
tmux_env = os .environ .pop ('TMUX' )
282
284
builder .session .switch_client ()
283
285
@@ -360,25 +362,31 @@ def command_freeze(args):
360
362
):
361
363
dest = None
362
364
while not dest :
363
- dest_prompt = prompt ('Save to: ' , os .path .abspath (
364
- os .path .join (config_dir , '%s.%s' % (sconf .get ('session_name' ), config_format ))))
365
+ save_to = os .path .abspath (
366
+ os .path .join (
367
+ config_dir ,
368
+ '%s.%s' % (sconf .get ('session_name' ), config_format )
369
+ )
370
+ )
371
+ dest_prompt = prompt ('Save to: ' , save_to )
365
372
if os .path .exists (dest_prompt ):
366
373
print ('%s exists. Pick a new filename.' % dest_prompt )
367
374
continue
368
375
369
376
dest = dest_prompt
370
377
371
378
dest = os .path .abspath (os .path .relpath (os .path .expanduser (dest )))
372
- if args .answer_yes or prompt_yes_no ('Write to %s?' % dest ):
379
+ if args .answer_yes or prompt_yes_no ('Save to %s?' % dest ):
373
380
buf = open (dest , 'w' )
374
381
buf .write (newconfig )
375
382
buf .close ()
376
383
377
384
print ('Saved to %s.' % dest )
378
385
else :
379
386
print (
380
- 'tmuxp has examples in JSON and YAML format at <http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
381
- 'View tmuxp docs at <http://tmuxp.readthedocs.org/>'
387
+ 'tmuxp has examples in JSON and YAML format at '
388
+ '<http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
389
+ 'View tmuxp docs at <http://tmuxp.readthedocs.org/>.'
382
390
)
383
391
sys .exit ()
384
392
@@ -445,7 +453,8 @@ def command_import_teamocil(args):
445
453
output = ''
446
454
447
455
if not os .path .exists (teamocil_config_dir ):
448
- output += '# %s: \n \t Directory doesn\' t exist.\n ' % teamocil_config_dir
456
+ output += '# %s: \n \t Directory doesn\' t exist.\n ' % \
457
+ teamocil_config_dir
449
458
elif not configs_in_user :
450
459
output += '# %s: \n \t None found.\n ' % teamocil_config_dir
451
460
else :
@@ -503,15 +512,16 @@ def command_import_teamocil(args):
503
512
dest = dest_prompt
504
513
505
514
dest = os .path .abspath (os .path .relpath (os .path .expanduser (dest )))
506
- if args .answer_yes or prompt_yes_no ('Write to %s?' % dest ):
515
+ if args .answer_yes or prompt_yes_no ('Save to %s?' % dest ):
507
516
buf = open (dest , 'w' )
508
517
buf .write (newconfig )
509
518
buf .close ()
510
519
511
520
print ('Saved to %s.' % dest )
512
521
else :
513
522
print (
514
- 'tmuxp has examples in JSON and YAML format at <http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
523
+ 'tmuxp has examples in JSON and YAML format at '
524
+ '<http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
515
525
'View tmuxp docs at <http://tmuxp.readthedocs.org/>'
516
526
)
517
527
sys .exit ()
@@ -531,7 +541,8 @@ def command_import_tmuxinator(args):
531
541
output = ''
532
542
533
543
if not os .path .exists (tmuxinator_config_dir ):
534
- output += '# %s: \n \t Directory doesn\' t exist.\n ' % tmuxinator_config_dir
544
+ output += '# %s: \n \t Directory doesn\' t exist.\n ' % \
545
+ tmuxinator_config_dir
535
546
elif not configs_in_user :
536
547
output += '# %s: \n \t None found.\n ' % tmuxinator_config_dir
537
548
else :
@@ -590,15 +601,16 @@ def command_import_tmuxinator(args):
590
601
dest = dest_prompt
591
602
592
603
dest = os .path .abspath (os .path .relpath (os .path .expanduser (dest )))
593
- if args .answer_yes or prompt_yes_no ('Write to %s?' % dest ):
604
+ if args .answer_yes or prompt_yes_no ('Save to %s?' % dest ):
594
605
buf = open (dest , 'w' )
595
606
buf .write (newconfig )
596
607
buf .close ()
597
608
598
609
print ('Saved to %s.' % dest )
599
610
else :
600
611
print (
601
- 'tmuxp has examples in JSON and YAML format at <http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
612
+ 'tmuxp has examples in JSON and YAML format at '
613
+ '<http://tmuxp.readthedocs.org/en/latest/examples.html>\n '
602
614
'View tmuxp docs at <http://tmuxp.readthedocs.org/>'
603
615
)
604
616
sys .exit ()
@@ -626,30 +638,38 @@ def command_convert(args):
626
638
return
627
639
628
640
if 'json' in ext :
629
- if args .answer_yes or prompt_yes_no ('convert to <%s> to yaml?' % (fullfile )):
641
+ if args .answer_yes or prompt_yes_no (
642
+ 'convert to <%s> to yaml?' % (fullfile )
643
+ ):
630
644
configparser = kaptan .Kaptan ()
631
645
configparser .import_config (configfile )
632
646
newfile = fullfile .replace (ext , '.yaml' )
633
647
newconfig = configparser .export (
634
648
'yaml' , indent = 2 , default_flow_style = False
635
649
)
636
- if args .answer_yes or prompt_yes_no ('write config to %s?' % (newfile )):
650
+ if args .answer_yes or prompt_yes_no (
651
+ 'Save config to %s?' % (newfile )
652
+ ):
637
653
buf = open (newfile , 'w' )
638
654
buf .write (newconfig )
639
655
buf .close ()
640
- print ('written new config to %s' % (newfile ))
656
+ print ('New config saved to %s' % (newfile ))
641
657
elif 'yaml' in ext :
642
- if args .answer_yes or prompt_yes_no ('convert to <%s> to json?' % (fullfile )):
658
+ if args .answer_yes or prompt_yes_no (
659
+ 'convert to <%s> to json?' % (fullfile )
660
+ ):
643
661
configparser = kaptan .Kaptan ()
644
662
configparser .import_config (configfile )
645
663
newfile = fullfile .replace (ext , '.json' )
646
664
newconfig = configparser .export ('json' , indent = 2 )
647
665
print (newconfig )
648
- if args .answer_yes or prompt_yes_no ('write config to <%s>?' % (newfile )):
666
+ if args .answer_yes or prompt_yes_no (
667
+ 'Save config to <%s>?' % (newfile )
668
+ ):
649
669
buf = open (newfile , 'w' )
650
670
buf .write (newconfig )
651
671
buf .close ()
652
- print ('written new config to <%s>.' % (newfile ))
672
+ print ('New config saved to <%s>.' % (newfile ))
653
673
654
674
655
675
def command_attach_session (args ):
@@ -706,6 +726,7 @@ def command_kill_session(args):
706
726
except exc .TmuxpException as e :
707
727
logger .error (e )
708
728
729
+
709
730
def get_parser ():
710
731
"""Return :py:class:`argparse.ArgumentParser` instance for CLI."""
711
732
@@ -837,7 +858,9 @@ def get_parser():
837
858
type = str ,
838
859
nargs = '?' ,
839
860
help = 'List config available in working directory and config folder.'
840
- ).completer = ConfigFileCompleter (allowednames = ('.yaml' , '.json' ), directories = False )
861
+ ).completer = ConfigFileCompleter (
862
+ allowednames = ('.yaml' , '.json' ), directories = False
863
+ )
841
864
load .set_defaults (callback = command_load )
842
865
843
866
convert = subparsers .add_parser (
@@ -850,7 +873,9 @@ def get_parser():
850
873
type = str ,
851
874
default = None ,
852
875
help = 'Absolute or relative path to config file.'
853
- ).completer = ConfigFileCompleter (allowednames = ('.yaml' , '.json' ), directories = False )
876
+ ).completer = ConfigFileCompleter (
877
+ allowednames = ('.yaml' , '.json' ), directories = False
878
+ )
854
879
855
880
convert .set_defaults (callback = command_convert )
856
881
@@ -921,14 +946,17 @@ def get_parser():
921
946
922
947
923
948
def main ():
949
+ """Main CLI application."""
924
950
925
951
parser = get_parser ()
926
952
927
953
argcomplete .autocomplete (parser , always_complete_options = False )
928
954
929
955
args = parser .parse_args ()
930
956
931
- setup_logger (level = args .log_level .upper () if 'log_level' in args else 'INFO' )
957
+ setup_logger (
958
+ level = args .log_level .upper () if 'log_level' in args else 'INFO'
959
+ )
932
960
933
961
try :
934
962
util .has_required_tmux_version ()
0 commit comments