Skip to content

Commit f93179d

Browse files
committed
refactor!: Rename config file to workspace file
1 parent b8befec commit f93179d

23 files changed

+139
-132
lines changed

docs/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ If you need an internal API stabilized please [file an issue](https://github.com
7070
### Finding
7171

7272
```{eval-rst}
73-
.. automethod:: tmuxp.config.is_config_file
73+
.. automethod:: tmuxp.config.is_workspace_file
7474
```
7575

7676
```{eval-rst}

docs/configuration/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Breaking down the basic configuration into sections:
105105
You can create a configuration and load it from anywhere in your file system.
106106

107107
```console
108-
$ tmuxp load [config_file]
108+
$ tmuxp load [workspace-file]
109109
```
110110

111111
````{tab} Relative

src/tmuxp/cli/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ def cli(_args: t.Optional[t.List[str]] = None) -> None:
147147
return
148148
elif import_subparser_name == "teamocil":
149149
command_import_teamocil(
150-
config_file=args.config_file,
150+
workspace_file=args.workspace_file,
151151
parser=parser,
152152
)
153153
elif import_subparser_name == "tmuxinator":
154154
command_import_tmuxinator(
155-
config_file=args.config_file,
155+
workspace_file=args.workspace_file,
156156
parser=parser,
157157
)
158158
elif args.subparser_name == "convert":
159159
command_convert(
160-
config_file=args.config_file,
160+
workspace_file=args.workspace_file,
161161
answer_yes=args.answer_yes,
162162
parser=parser,
163163
)
@@ -166,7 +166,7 @@ def cli(_args: t.Optional[t.List[str]] = None) -> None:
166166

167167
elif args.subparser_name == "edit":
168168
command_edit(
169-
config_file=args.config_file,
169+
workspace_file=args.workspace_file,
170170
parser=parser,
171171
)
172172
elif args.subparser_name == "freeze":

src/tmuxp/cli/convert.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
def create_convert_subparser(
1212
parser: argparse.ArgumentParser,
1313
) -> argparse.ArgumentParser:
14-
config_file = parser.add_argument(
15-
dest="config_file",
14+
workspace_file = parser.add_argument(
15+
dest="workspace_file",
1616
type=str,
1717
metavar="config-file",
1818
help="checks tmuxp and current directory for config files.",
1919
)
2020
try:
2121
import shtab
2222

23-
config_file.complete = shtab.FILE # type: ignore
23+
workspace_file.complete = shtab.FILE # type: ignore
2424
except ImportError:
2525
pass
2626

@@ -35,17 +35,17 @@ def create_convert_subparser(
3535

3636

3737
def command_convert(
38-
config_file: t.Union[str, pathlib.Path],
38+
workspace_file: t.Union[str, pathlib.Path],
3939
answer_yes: bool,
4040
parser: t.Optional[argparse.ArgumentParser] = None,
4141
) -> None:
4242
"""Convert a tmuxp config between JSON and YAML."""
43-
config_file = scan_config(config_file, config_dir=get_config_dir())
43+
workspace_file = scan_config(workspace_file, config_dir=get_config_dir())
4444

45-
if isinstance(config_file, str):
46-
config_file = pathlib.Path(config_file)
45+
if isinstance(workspace_file, str):
46+
workspace_file = pathlib.Path(workspace_file)
4747

48-
_, ext = os.path.splitext(config_file)
48+
_, ext = os.path.splitext(workspace_file)
4949
ext = ext.lower()
5050
if ext == ".json":
5151
to_filetype = "yaml"
@@ -54,14 +54,14 @@ def command_convert(
5454
else:
5555
raise Exception(f"Unknown filetype: {ext} (valid: [.json, .yaml, .yml])")
5656

57-
configparser = ConfigReader.from_file(config_file)
58-
newfile = config_file.parent / (str(config_file.stem) + f".{to_filetype}")
57+
configparser = ConfigReader.from_file(workspace_file)
58+
newfile = workspace_file.parent / (str(workspace_file.stem) + f".{to_filetype}")
5959

6060
export_kwargs = {"default_flow_style": False} if to_filetype == "yaml" else {}
6161
new_config = configparser.dump(format=to_filetype, indent=2, **export_kwargs)
6262

6363
if not answer_yes:
64-
if prompt_yes_no(f"Convert to <{config_file}> to {to_filetype}?"):
64+
if prompt_yes_no(f"Convert to <{workspace_file}> to {to_filetype}?"):
6565
if prompt_yes_no("Save config to %s?" % newfile):
6666
answer_yes = True
6767

src/tmuxp/cli/edit.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ def create_edit_subparser(
1111
parser: argparse.ArgumentParser,
1212
) -> argparse.ArgumentParser:
1313
parser.add_argument(
14-
dest="config_file",
15-
metavar="config-file",
14+
dest="workspace_file",
15+
metavar="workspace-file",
1616
type=str,
1717
help="checks current tmuxp and current directory for config files.",
1818
)
1919
return parser
2020

2121

2222
def command_edit(
23-
config_file: t.Union[str, pathlib.Path],
23+
workspace_file: t.Union[str, pathlib.Path],
2424
parser: t.Optional[argparse.ArgumentParser] = None,
2525
):
26-
config_file = scan_config(config_file)
26+
workspace_file = scan_config(workspace_file)
2727

2828
sys_editor = os.environ.get("EDITOR", "vim")
29-
subprocess.call([sys_editor, config_file])
29+
subprocess.call([sys_editor, workspace_file])

src/tmuxp/cli/import_config.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _resolve_path_no_overwrite(config: str) -> str:
5555

5656

5757
def command_import(
58-
config_file: str,
58+
workspace_file: str,
5959
print_list: str,
6060
parser: argparse.ArgumentParser,
6161
):
@@ -74,8 +74,8 @@ def create_import_subparser(
7474
)
7575

7676
import_teamocilgroup = import_teamocil.add_mutually_exclusive_group(required=True)
77-
teamocil_config_file = import_teamocilgroup.add_argument(
78-
dest="config_file",
77+
teamocil_workspace_file = import_teamocilgroup.add_argument(
78+
dest="workspace_file",
7979
type=str,
8080
nargs="?",
8181
metavar="config-file",
@@ -92,8 +92,8 @@ def create_import_subparser(
9292
import_tmuxinatorgroup = import_tmuxinator.add_mutually_exclusive_group(
9393
required=True
9494
)
95-
tmuxinator_config_file = import_tmuxinatorgroup.add_argument(
96-
dest="config_file",
95+
tmuxinator_workspace_file = import_tmuxinatorgroup.add_argument(
96+
dest="workspace_file",
9797
type=str,
9898
nargs="?",
9999
metavar="config-file",
@@ -107,20 +107,20 @@ def create_import_subparser(
107107
try:
108108
import shtab
109109

110-
teamocil_config_file.complete = shtab.FILE # type: ignore
111-
tmuxinator_config_file.complete = shtab.FILE # type: ignore
110+
teamocil_workspace_file.complete = shtab.FILE # type: ignore
111+
tmuxinator_workspace_file.complete = shtab.FILE # type: ignore
112112
except ImportError:
113113
pass
114114

115115
return parser
116116

117117

118118
def import_config(
119-
config_file: str,
119+
workspace_file: str,
120120
importfunc: t.Callable,
121121
parser: t.Optional[argparse.ArgumentParser] = None,
122122
) -> None:
123-
existing_config = ConfigReader._from_file(pathlib.Path(config_file))
123+
existing_config = ConfigReader._from_file(pathlib.Path(workspace_file))
124124
cfg_reader = ConfigReader(importfunc(existing_config))
125125

126126
config_format = prompt_choices(
@@ -167,21 +167,21 @@ def import_config(
167167

168168

169169
def command_import_tmuxinator(
170-
config_file: str,
170+
workspace_file: str,
171171
parser: t.Optional[argparse.ArgumentParser] = None,
172172
) -> None:
173-
"""Convert a tmuxinator config from config_file to tmuxp format and import
173+
"""Convert a tmuxinator config from workspace_file to tmuxp format and import
174174
it into tmuxp."""
175-
config_file = scan_config(config_file, config_dir=get_tmuxinator_dir())
176-
import_config(config_file, config.import_tmuxinator)
175+
workspace_file = scan_config(workspace_file, config_dir=get_tmuxinator_dir())
176+
import_config(workspace_file, config.import_tmuxinator)
177177

178178

179179
def command_import_teamocil(
180-
config_file: str,
180+
workspace_file: str,
181181
parser: t.Optional[argparse.ArgumentParser] = None,
182182
) -> None:
183-
"""Convert a teamocil config from config_file to tmuxp format and import
183+
"""Convert a teamocil config from workspace_file to tmuxp format and import
184184
it into tmuxp."""
185-
config_file = scan_config(config_file, config_dir=get_teamocil_dir())
185+
workspace_file = scan_config(workspace_file, config_dir=get_teamocil_dir())
186186

187-
import_config(config_file, config.import_teamocil)
187+
import_config(workspace_file, config.import_teamocil)

src/tmuxp/cli/load.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class OptionOverrides(TypedDict):
4040

4141

4242
class CLILoadNamespace(argparse.Namespace):
43-
config_files: t.List[str]
43+
workspace_files: t.List[str]
4444
socket_name: t.Optional[str]
4545
socket_path: t.Optional[str]
4646
tmux_config_file: t.Optional[str]
@@ -256,7 +256,7 @@ def _setup_plugins(builder: WorkspaceBuilder) -> Session:
256256

257257

258258
def load_workspace(
259-
config_file: StrPath,
259+
workspace_file: StrPath,
260260
socket_name: t.Optional[str] = None,
261261
socket_path: None = None,
262262
tmux_config_file: None = None,
@@ -271,7 +271,7 @@ def load_workspace(
271271
272272
Parameters
273273
----------
274-
config_file : list of str
274+
workspace_file : list of str
275275
paths or session names to workspace files
276276
socket_name : str, optional
277277
``tmux -L <socket-name>``
@@ -361,18 +361,19 @@ def load_workspace(
361361
Accessed April 8th, 2018.
362362
"""
363363
# get the canonical path, eliminating any symlinks
364-
if isinstance(config_file, (str, os.PathLike)):
365-
config_file = pathlib.Path(config_file)
364+
if isinstance(workspace_file, (str, os.PathLike)):
365+
workspace_file = pathlib.Path(workspace_file)
366366

367367
tmuxp_echo(
368-
style("[Loading] ", fg="green") + style(str(config_file), fg="blue", bold=True)
368+
style("[Loading] ", fg="green")
369+
+ style(str(workspace_file), fg="blue", bold=True)
369370
)
370371

371372
# ConfigReader allows us to open a yaml or json file as a dict
372-
raw_config = config_reader.ConfigReader._from_file(config_file) or {}
373+
raw_config = config_reader.ConfigReader._from_file(workspace_file) or {}
373374

374375
# shapes configurations relative to config / profile file location
375-
sconfig = config.expand(raw_config, cwd=os.path.dirname(config_file))
376+
sconfig = config.expand(raw_config, cwd=os.path.dirname(workspace_file))
376377
# Overwrite session name
377378
if new_session_name:
378379
sconfig["session_name"] = new_session_name
@@ -382,7 +383,7 @@ def load_workspace(
382383
t = Server( # create tmux server object
383384
socket_name=socket_name,
384385
socket_path=socket_path,
385-
config_file=tmux_config_file,
386+
workspace_file=tmux_config_file,
386387
colors=colors,
387388
)
388389

@@ -393,7 +394,7 @@ def load_workspace(
393394
sconf=sconfig, plugins=load_plugins(sconfig), server=t
394395
)
395396
except exc.EmptyConfigException:
396-
tmuxp_echo("%s is empty or parsed no config data" % config_file)
397+
tmuxp_echo("%s is empty or parsed no config data" % workspace_file)
397398
return None
398399

399400
session_name = sconfig["session_name"]
@@ -468,7 +469,7 @@ def load_workspace(
468469
return _setup_plugins(builder)
469470

470471

471-
def config_file_completion(ctx, params, incomplete):
472+
def workspace_file_completion(ctx, params, incomplete):
472473
config_dir = pathlib.Path(get_config_dir())
473474
choices: t.List[pathlib.Path] = []
474475

@@ -491,8 +492,8 @@ def config_file_completion(ctx, params, incomplete):
491492

492493

493494
def create_load_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
494-
config_files = parser.add_argument(
495-
"config_files",
495+
workspace_files = parser.add_argument(
496+
"workspace_files",
496497
nargs="+",
497498
metavar="config-file",
498499
help="filepath to session or filename of session if in tmuxp config directory",
@@ -574,7 +575,7 @@ def create_load_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentP
574575
try:
575576
import shtab
576577

577-
config_files.complete = shtab.FILE # type: ignore
578+
workspace_files.complete = shtab.FILE # type: ignore
578579
tmux_config_file.complete = shtab.FILE # type: ignore
579580
log_file.complete = shtab.FILE # type: ignore
580581
except ImportError:
@@ -629,19 +630,19 @@ def command_load(
629630
"append": args.append,
630631
}
631632

632-
if args.config_files is None or len(args.config_files) == 0:
633+
if args.workspace_files is None or len(args.workspace_files) == 0:
633634
tmuxp_echo("Enter at least one config")
634635
if parser is not None:
635636
parser.print_help()
636637
sys.exit()
637638
return
638639

639-
last_idx = len(args.config_files) - 1
640+
last_idx = len(args.workspace_files) - 1
640641
original_detached_option = tmux_options.pop("detached")
641642
original_new_session_name = tmux_options.pop("new_session_name")
642643

643-
for idx, config_file in enumerate(args.config_files):
644-
config_file = scan_config(config_file, config_dir=get_config_dir())
644+
for idx, workspace_file in enumerate(args.workspace_files):
645+
workspace_file = scan_config(workspace_file, config_dir=get_config_dir())
645646

646647
detached = original_detached_option
647648
new_session_name = original_new_session_name
@@ -651,7 +652,7 @@ def command_load(
651652
new_session_name = None
652653

653654
load_workspace(
654-
config_file,
655+
workspace_file,
655656
detached=detached,
656657
new_session_name=new_session_name,
657658
**tmux_options,

src/tmuxp/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def validate_schema(session_config):
4545
return True
4646

4747

48-
def is_config_file(filename, extensions=[".yml", ".yaml", ".json"]):
48+
def is_workspace_file(filename, extensions=[".yml", ".yaml", ".json"]):
4949
"""
5050
Return True if file has a valid config file type.
5151
@@ -84,7 +84,7 @@ def in_dir(
8484
configs = []
8585

8686
for filename in os.listdir(config_dir):
87-
if is_config_file(filename, extensions) and not filename.startswith("."):
87+
if is_workspace_file(filename, extensions) and not filename.startswith("."):
8888
configs.append(filename)
8989

9090
return configs
@@ -109,7 +109,7 @@ def in_cwd():
109109
configs = []
110110

111111
for filename in os.listdir(os.getcwd()):
112-
if filename.startswith(".tmuxp") and is_config_file(filename):
112+
if filename.startswith(".tmuxp") and is_workspace_file(filename):
113113
configs.append(filename)
114114

115115
return configs

tests/fixtures/config/expand2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
def unexpanded_yaml():
7-
return test_utils.read_config_file("config/expand2-unexpanded.yaml")
7+
return test_utils.read_workspace_file("config/expand2-unexpanded.yaml")
88

99

1010
def expanded_yaml():
11-
return test_utils.read_config_file("config/expand2-expanded.yaml").format(
11+
return test_utils.read_workspace_file("config/expand2-expanded.yaml").format(
1212
HOME=os.path.expanduser("~")
1313
)

0 commit comments

Comments
 (0)