@@ -42,6 +42,14 @@ def get_cwd():
42
42
return os .getcwd ()
43
43
44
44
45
+ def tmuxp_echo (message = None , log_level = 'INFO' , ** click_kwargs ):
46
+ """
47
+ Combines logging.log and click.echo
48
+ """
49
+ logger .log (log .LOG_LEVELS [log_level ], click .unstyle (message ))
50
+ click .echo (message , ** click_kwargs )
51
+
52
+
45
53
def get_config_dir ():
46
54
"""
47
55
Return tmuxp configuration directory.
@@ -246,8 +254,8 @@ def scan_config_argument(ctx, param, value, config_dir=None):
246
254
config_dir = config_dir ()
247
255
248
256
if not config :
249
- click . echo ("Enter at least one CONFIG" )
250
- click . echo (ctx .get_help (), color = ctx .color )
257
+ tmuxp_echo ("Enter at least one CONFIG" )
258
+ tmuxp_echo (ctx .get_help (), color = ctx .color )
251
259
ctx .exit ()
252
260
253
261
if isinstance (value , string_types ):
@@ -357,11 +365,14 @@ def scan_config(config, config_dir=None):
357
365
]
358
366
359
367
if len (candidates ) > 1 :
360
- click .secho (
361
- 'Multiple .tmuxp.{yml,yaml,json} configs in %s' % dirname (config ),
362
- fg = "red" ,
368
+ tmuxp_echo (
369
+ click .style (
370
+ 'Multiple .tmuxp.{yml,yaml,json} configs in %s'
371
+ % dirname (config ),
372
+ fg = "red" ,
373
+ )
363
374
)
364
- click . echo (
375
+ tmuxp_echo (
365
376
click .wrap_text (
366
377
'This is undefined behavior, use only one. '
367
378
'Use file names e.g. myproject.json, coolproject.yaml. '
@@ -381,7 +392,46 @@ def scan_config(config, config_dir=None):
381
392
return config
382
393
383
394
395
+ < << << << Updated upstream
384
396
def _reattach (session ):
397
+ == == == =
398
+ def load_plugins (sconf ):
399
+ """
400
+ Load and return plugins in config
401
+ """
402
+ plugins = []
403
+ if 'plugins' in sconf :
404
+ for plugin in sconf ['plugins' ]:
405
+ try :
406
+ module_name = plugin .split ('.' )
407
+ module_name = '.' .join (module_name [:- 1 ])
408
+ plugin_name = plugin .split ('.' )[- 1 ]
409
+ plugin = getattr (importlib .import_module (module_name ), plugin_name )
410
+ plugins .append (plugin ())
411
+ except exc .TmuxpPluginException as error :
412
+ if not click .confirm (
413
+ '%sSkip loading %s?'
414
+ % (click .style (str (error ), fg = 'yellow' ), plugin_name ),
415
+ default = True ,
416
+ ):
417
+ tmuxp_echo (
418
+ click .style ('[Not Skipping] ' , fg = 'yellow' )
419
+ + 'Plugin versions constraint not met. Exiting...'
420
+ )
421
+ sys .exit (1 )
422
+ except Exception as error :
423
+ tmuxp_echo (
424
+ click .style ('[Plugin Error] ' , fg = 'red' )
425
+ + "Couldn\' t load {0}\n " .format (plugin )
426
+ + click .style ('{0}' .format (error ), fg = 'yellow' )
427
+ )
428
+ sys .exit (1 )
429
+
430
+ return plugins
431
+
432
+
433
+ def _reattach (builder ):
434
+ > >> >> >> Stashed changes
385
435
"""
386
436
Reattach session (depending on env being inside tmux already or not)
387
437
@@ -505,6 +555,11 @@ def load_workspace(
505
555
# get the canonical path, eliminating any symlinks
506
556
config_file = os .path .realpath (config_file )
507
557
558
+ tmuxp_echo (
559
+ click .style ('[Loading] ' , fg = 'green' )
560
+ + click .style (config_file , fg = 'blue' , bold = True )
561
+ )
562
+
508
563
# kaptan allows us to open a yaml or json file as a dict
509
564
sconfig = kaptan .Kaptan ()
510
565
sconfig = sconfig .import_config (config_file ).get ()
@@ -525,7 +580,7 @@ def load_workspace(
525
580
try : # load WorkspaceBuilder object for tmuxp config / tmux server
526
581
builder = WorkspaceBuilder (sconf = sconfig , server = t )
527
582
except exc .EmptyConfigException :
528
- click . echo ('%s is empty or parsed no config data' % config_file , err = True )
583
+ tmuxp_echo ('%s is empty or parsed no config data' % config_file , err = True )
529
584
return
530
585
531
586
session_name = sconfig ['session_name' ]
@@ -545,11 +600,6 @@ def load_workspace(
545
600
return
546
601
547
602
try :
548
- click .echo (
549
- click .style ('[Loading] ' , fg = 'green' )
550
- + click .style (config_file , fg = 'blue' , bold = True )
551
- )
552
-
553
603
builder .build () # load tmux session via workspace builder
554
604
555
605
if 'TMUX' in os .environ : # tmuxp ran from inside tmux
@@ -586,8 +636,8 @@ def load_workspace(
586
636
except exc .TmuxpException as e :
587
637
import traceback
588
638
589
- click . echo (traceback .format_exc (), err = True )
590
- click . echo (e , err = True )
639
+ tmuxp_echo (traceback .format_exc (), err = True )
640
+ tmuxp_echo (e , err = True )
591
641
592
642
choice = click .prompt (
593
643
'Error loading workspace. (k)ill, (a)ttach, (d)etach?' ,
@@ -597,7 +647,7 @@ def load_workspace(
597
647
598
648
if choice == 'k' :
599
649
builder .session .kill_session ()
600
- click . echo ('Session killed.' )
650
+ tmuxp_echo ('Session killed.' )
601
651
elif choice == 'a' :
602
652
if 'TMUX' in os .environ :
603
653
builder .session .switch_client ()
@@ -625,12 +675,12 @@ def cli(log_level):
625
675
try :
626
676
has_minimum_version ()
627
677
except TmuxCommandNotFound :
628
- click . echo ('tmux not found. tmuxp requires you install tmux first.' )
678
+ tmuxp_echo ('tmux not found. tmuxp requires you install tmux first.' )
629
679
sys .exit ()
630
680
except exc .TmuxpException as e :
631
- click . echo (e , err = True )
681
+ tmuxp_echo (e , err = True )
632
682
sys .exit ()
633
- setup_logger (level = log_level .upper ())
683
+ setup_logger (logger = logger , level = log_level .upper ())
634
684
635
685
636
686
def setup_logger (logger = None , level = 'INFO' ):
@@ -649,12 +699,12 @@ def setup_logger(logger=None, level='INFO'):
649
699
logger = logging .getLogger ()
650
700
651
701
if not logger .handlers : # setup logger handlers
652
- channel = logging .StreamHandler ()
653
- channel .setFormatter (log .DebugLogFormatter ())
654
-
702
+ # channel = logging.StreamHandler()
703
+ # channel.setFormatter(log.DebugLogFormatter())
655
704
# channel.setFormatter(log.LogFormatter())
705
+
656
706
logger .setLevel (level )
657
- logger .addHandler (channel )
707
+ # logger.addHandler(channel)
658
708
659
709
660
710
def startup (config_dir ):
@@ -875,6 +925,7 @@ def command_freeze(session_name, socket_name, socket_path, force):
875
925
flag_value = 88 ,
876
926
help = 'Like -2, but indicates that the terminal supports 88 colours.' ,
877
927
)
928
+ @click .option ('--log-file' , help = 'File to log errors/output to' )
878
929
def command_load (
879
930
ctx ,
880
931
config ,
@@ -884,6 +935,7 @@ def command_load(
884
935
answer_yes ,
885
936
detached ,
886
937
colors ,
938
+ log_file ,
887
939
):
888
940
"""Load a tmux workspace from each CONFIG.
889
941
@@ -908,6 +960,10 @@ def command_load(
908
960
detached mode.
909
961
"""
910
962
util .oh_my_zsh_auto_title ()
963
+ if log_file :
964
+ logfile_handler = logging .FileHandler (log_file )
965
+ logfile_handler .setFormatter (log .LogFormatter ())
966
+ logger .addHandler (logfile_handler )
911
967
912
968
tmux_options = {
913
969
'socket_name' : socket_name ,
@@ -919,8 +975,8 @@ def command_load(
919
975
}
920
976
921
977
if not config :
922
- click . echo ("Enter at least one CONFIG" )
923
- click . echo (ctx .get_help (), color = ctx .color )
978
+ tmuxp_echo ("Enter at least one CONFIG" )
979
+ tmuxp_echo (ctx .get_help (), color = ctx .color )
924
980
ctx .exit ()
925
981
926
982
if isinstance (config , string_types ):
@@ -962,7 +1018,7 @@ def import_config(configfile, importfunc):
962
1018
else :
963
1019
sys .exit ('Unknown config format.' )
964
1020
965
- click . echo (
1021
+ tmuxp_echo (
966
1022
newconfig + '---------------------------------------------------------------'
967
1023
'\n '
968
1024
'Configuration import does its best to convert files.\n '
@@ -984,9 +1040,9 @@ def import_config(configfile, importfunc):
984
1040
buf .write (newconfig )
985
1041
buf .close ()
986
1042
987
- click . echo ('Saved to %s.' % dest )
1043
+ tmuxp_echo ('Saved to %s.' % dest )
988
1044
else :
989
- click . echo (
1045
+ tmuxp_echo (
990
1046
'tmuxp has examples in JSON and YAML format at '
991
1047
'<http://tmuxp.git-pull.com/examples.html>\n '
992
1048
'View tmuxp docs at <http://tmuxp.git-pull.com/>'
@@ -1125,4 +1181,4 @@ def format_tmux_resp(std_resp):
1125
1181
% format_tmux_resp (tmux_cmd ('show-window-options' , '-g' )),
1126
1182
]
1127
1183
1128
- click . echo ('\n ' .join (output ))
1184
+ tmuxp_echo ('\n ' .join (output ))
0 commit comments