2222
2323
2424import 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+ )
2628verstrline = open (VERSIONFILE , "rt" ).read ()
2729VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
2830mo = re .search (VSRE , verstrline , re .M )
2931if mo :
3032 __version__ = mo .group (1 )
31- #import pkg_resources
32- #__version__ = pkg_resources.require("tmuxp")[0].version
3333
3434logger = logging .getLogger (__name__ )
3535
@@ -277,7 +277,9 @@ def load_workspace(config_file, args):
277277 builder .build ()
278278
279279 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+ ):
281283 tmux_env = os .environ .pop ('TMUX' )
282284 builder .session .switch_client ()
283285
@@ -360,25 +362,31 @@ def command_freeze(args):
360362 ):
361363 dest = None
362364 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 )
365372 if os .path .exists (dest_prompt ):
366373 print ('%s exists. Pick a new filename.' % dest_prompt )
367374 continue
368375
369376 dest = dest_prompt
370377
371378 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 ):
373380 buf = open (dest , 'w' )
374381 buf .write (newconfig )
375382 buf .close ()
376383
377384 print ('Saved to %s.' % dest )
378385 else :
379386 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/>.'
382390 )
383391 sys .exit ()
384392
@@ -445,7 +453,8 @@ def command_import_teamocil(args):
445453 output = ''
446454
447455 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
449458 elif not configs_in_user :
450459 output += '# %s: \n \t None found.\n ' % teamocil_config_dir
451460 else :
@@ -503,15 +512,16 @@ def command_import_teamocil(args):
503512 dest = dest_prompt
504513
505514 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 ):
507516 buf = open (dest , 'w' )
508517 buf .write (newconfig )
509518 buf .close ()
510519
511520 print ('Saved to %s.' % dest )
512521 else :
513522 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 '
515525 'View tmuxp docs at <http://tmuxp.readthedocs.org/>'
516526 )
517527 sys .exit ()
@@ -531,7 +541,8 @@ def command_import_tmuxinator(args):
531541 output = ''
532542
533543 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
535546 elif not configs_in_user :
536547 output += '# %s: \n \t None found.\n ' % tmuxinator_config_dir
537548 else :
@@ -590,15 +601,16 @@ def command_import_tmuxinator(args):
590601 dest = dest_prompt
591602
592603 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 ):
594605 buf = open (dest , 'w' )
595606 buf .write (newconfig )
596607 buf .close ()
597608
598609 print ('Saved to %s.' % dest )
599610 else :
600611 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 '
602614 'View tmuxp docs at <http://tmuxp.readthedocs.org/>'
603615 )
604616 sys .exit ()
@@ -626,30 +638,38 @@ def command_convert(args):
626638 return
627639
628640 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+ ):
630644 configparser = kaptan .Kaptan ()
631645 configparser .import_config (configfile )
632646 newfile = fullfile .replace (ext , '.yaml' )
633647 newconfig = configparser .export (
634648 'yaml' , indent = 2 , default_flow_style = False
635649 )
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+ ):
637653 buf = open (newfile , 'w' )
638654 buf .write (newconfig )
639655 buf .close ()
640- print ('written new config to %s' % (newfile ))
656+ print ('New config saved to %s' % (newfile ))
641657 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+ ):
643661 configparser = kaptan .Kaptan ()
644662 configparser .import_config (configfile )
645663 newfile = fullfile .replace (ext , '.json' )
646664 newconfig = configparser .export ('json' , indent = 2 )
647665 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+ ):
649669 buf = open (newfile , 'w' )
650670 buf .write (newconfig )
651671 buf .close ()
652- print ('written new config to <%s>.' % (newfile ))
672+ print ('New config saved to <%s>.' % (newfile ))
653673
654674
655675def command_attach_session (args ):
@@ -706,6 +726,7 @@ def command_kill_session(args):
706726 except exc .TmuxpException as e :
707727 logger .error (e )
708728
729+
709730def get_parser ():
710731 """Return :py:class:`argparse.ArgumentParser` instance for CLI."""
711732
@@ -837,7 +858,9 @@ def get_parser():
837858 type = str ,
838859 nargs = '?' ,
839860 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+ )
841864 load .set_defaults (callback = command_load )
842865
843866 convert = subparsers .add_parser (
@@ -850,7 +873,9 @@ def get_parser():
850873 type = str ,
851874 default = None ,
852875 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+ )
854879
855880 convert .set_defaults (callback = command_convert )
856881
@@ -921,14 +946,17 @@ def get_parser():
921946
922947
923948def main ():
949+ """Main CLI application."""
924950
925951 parser = get_parser ()
926952
927953 argcomplete .autocomplete (parser , always_complete_options = False )
928954
929955 args = parser .parse_args ()
930956
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+ )
932960
933961 try :
934962 util .has_required_tmux_version ()
0 commit comments