|
4 | 4 | ~~~~~~~~~~~~
|
5 | 5 |
|
6 | 6 | """
|
7 |
| -import copy |
8 | 7 | import logging
|
9 | 8 | import os
|
| 9 | +from typing import Dict |
10 | 10 |
|
11 | 11 | from . import exc
|
12 | 12 |
|
@@ -168,6 +168,32 @@ def inline(sconf):
|
168 | 168 | return sconf
|
169 | 169 |
|
170 | 170 |
|
| 171 | +def expand_cmd(p: Dict) -> Dict: |
| 172 | + if isinstance(p, str): |
| 173 | + p = {"shell_command": [p]} |
| 174 | + elif not p: |
| 175 | + p = {"shell_command": []} |
| 176 | + |
| 177 | + assert isinstance(p, dict) |
| 178 | + if "shell_command" in p: |
| 179 | + cmd = p["shell_command"] |
| 180 | + |
| 181 | + if isinstance(p["shell_command"], str): |
| 182 | + cmd = [cmd] |
| 183 | + |
| 184 | + if not cmd or any(a == cmd for a in [None, "blank", "pane"]): |
| 185 | + cmd = [] |
| 186 | + |
| 187 | + if isinstance(cmd, list) and len(cmd) == int(1): |
| 188 | + if any(a in cmd for a in [None, "blank", "pane"]): |
| 189 | + cmd = [] |
| 190 | + |
| 191 | + p["shell_command"] = cmd |
| 192 | + else: |
| 193 | + p["shell_command"] = [] |
| 194 | + return p |
| 195 | + |
| 196 | + |
171 | 197 | def expand(sconf, cwd=None, parent=None):
|
172 | 198 | """Return config with shorthand and inline properties expanded.
|
173 | 199 |
|
@@ -278,35 +304,9 @@ def expand(sconf, cwd=None, parent=None):
|
278 | 304 | sconf["windows"] = [expand(window, parent=sconf) for window in sconf["windows"]]
|
279 | 305 | elif "panes" in sconf:
|
280 | 306 | pane_configs = sconf["panes"]
|
281 |
| - for pconf in pane_configs: |
282 |
| - p_index = pane_configs.index(pconf) |
283 |
| - p = copy.deepcopy(pconf) |
284 |
| - pconf = pane_configs[p_index] = {} |
285 |
| - |
286 |
| - if isinstance(p, str): |
287 |
| - p = {"shell_command": [p]} |
288 |
| - elif not p: |
289 |
| - p = {"shell_command": []} |
290 |
| - |
291 |
| - assert isinstance(p, dict) |
292 |
| - if "shell_command" in p: |
293 |
| - cmd = p["shell_command"] |
294 |
| - |
295 |
| - if isinstance(p["shell_command"], str): |
296 |
| - cmd = [cmd] |
297 |
| - |
298 |
| - if not cmd or any(a == cmd for a in [None, "blank", "pane"]): |
299 |
| - cmd = [] |
300 |
| - |
301 |
| - if isinstance(cmd, list) and len(cmd) == int(1): |
302 |
| - if any(a in cmd for a in [None, "blank", "pane"]): |
303 |
| - cmd = [] |
304 |
| - |
305 |
| - p["shell_command"] = cmd |
306 |
| - else: |
307 |
| - p["shell_command"] = [] |
308 |
| - |
309 |
| - pconf.update(p) |
| 307 | + for pane_idx, pconf in enumerate(pane_configs): |
| 308 | + pane_configs[pane_idx] = {} |
| 309 | + pane_configs[pane_idx].update(expand_cmd(pconf)) |
310 | 310 | sconf["panes"] = [expand(pane, parent=sconf) for pane in pane_configs]
|
311 | 311 |
|
312 | 312 | return sconf
|
|
0 commit comments