1
+ from libtmux .pane import Pane
2
+ from libtmux .session import Session
3
+ import typing as t
4
+
5
+
1
6
def inline (workspace_dict ):
2
7
"""Return workspace with inlined shorthands. Opposite of :meth:`loader.expand`.
3
8
@@ -40,7 +45,7 @@ def inline(workspace_dict):
40
45
return workspace_dict
41
46
42
47
43
- def freeze (session ) :
48
+ def freeze (session : Session ) -> t . Dict [ str , t . Any ] :
44
49
"""Freeze live tmux session into a tmuxp workspacee.
45
50
46
51
Parameters
@@ -53,53 +58,61 @@ def freeze(session):
53
58
dict
54
59
tmuxp compatible workspace
55
60
"""
56
- sconf = {"session_name" : session .session_name , "windows" : []}
57
-
58
- for w in session .windows :
59
- wconf = {
60
- "options" : w .show_window_options (),
61
- "window_name" : w .name ,
62
- "layout" : w .window_layout ,
61
+ session_config : t .Dict [str , t .Any ] = {
62
+ "session_name" : session .session_name ,
63
+ "windows" : [],
64
+ }
65
+
66
+ for window in session .windows :
67
+ window_config : t .Dict [str , t .Any ] = {
68
+ "options" : window .show_window_options (),
69
+ "window_name" : window .name ,
70
+ "layout" : window .window_layout ,
63
71
"panes" : [],
64
72
}
65
- if getattr (w , "window_active" , "0" ) == "1" :
66
- wconf ["focus" ] = "true"
73
+
74
+ if getattr (window , "window_active" , "0" ) == "1" :
75
+ window_config ["focus" ] = "true"
67
76
68
77
# If all panes have same path, set 'start_directory' instead
69
78
# of using 'cd' shell commands.
70
- def pane_has_same_path (p ) :
71
- return w .panes [0 ].pane_current_path == p .pane_current_path
79
+ def pane_has_same_path (pane : Pane ) -> bool :
80
+ return window .panes [0 ].pane_current_path == pane .pane_current_path
72
81
73
- if all (pane_has_same_path (p ) for p in w .panes ):
74
- wconf ["start_directory" ] = w .panes [0 ].pane_current_path
82
+ if all (pane_has_same_path (pane = pane ) for pane in window .panes ):
83
+ window_config ["start_directory" ] = window .panes [0 ].pane_current_path
75
84
76
- for p in w .panes :
77
- pconf = {"shell_command" : []}
85
+ for pane in window .panes :
86
+ pane_config : t .Union [str , t .Dict [str , t .Any ]] = {"shell_command" : []}
87
+ assert isinstance (pane_config , dict )
78
88
79
- if "start_directory" not in wconf :
80
- pconf ["shell_command" ].append ("cd " + p .pane_current_path )
89
+ if "start_directory" not in window_config and pane . pane_current_path :
90
+ pane_config ["shell_command" ].append ("cd " + pane .pane_current_path )
81
91
82
- if getattr (p , "pane_active" , "0" ) == "1" :
83
- pconf ["focus" ] = "true"
92
+ if getattr (pane , "pane_active" , "0" ) == "1" :
93
+ pane_config ["focus" ] = "true"
84
94
85
- current_cmd = p .pane_current_command
95
+ current_cmd = pane .pane_current_command
86
96
87
- def filter_interpretters_and_shells ():
88
- return current_cmd .startswith ("-" ) or any (
89
- current_cmd .endswith (cmd ) for cmd in ["python" , "ruby" , "node" ]
97
+ def filter_interpretters_and_shells () -> bool :
98
+ return current_cmd is not None and (
99
+ current_cmd .startswith ("-" )
100
+ or any (
101
+ current_cmd .endswith (cmd ) for cmd in ["python" , "ruby" , "node" ]
102
+ )
90
103
)
91
104
92
105
if filter_interpretters_and_shells ():
93
106
current_cmd = None
94
107
95
108
if current_cmd :
96
- pconf ["shell_command" ].append (current_cmd )
109
+ pane_config ["shell_command" ].append (current_cmd )
97
110
else :
98
- if not len (pconf ["shell_command" ]):
99
- pconf = "pane"
111
+ if not len (pane_config ["shell_command" ]):
112
+ pane_config = "pane"
100
113
101
- wconf ["panes" ].append (pconf )
114
+ window_config ["panes" ].append (pane_config )
102
115
103
- sconf ["windows" ].append (wconf )
116
+ session_config ["windows" ].append (window_config )
104
117
105
- return sconf
118
+ return session_config
0 commit comments