diff --git a/comeback/plugins/terminal/__init__.py b/comeback/plugins/terminal/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/comeback/plugins/terminal/main.py b/comeback/plugins/terminal/main.py new file mode 100644 index 0000000..b4e5672 --- /dev/null +++ b/comeback/plugins/terminal/main.py @@ -0,0 +1,50 @@ +import pathlib +from typing import Optional + +from comeback import utils + + +def check_plugin(cwd: Optional[str] = None) -> utils.RUN_STATUS: + """Test if we can use this plugin""" + if cwd is None: + return False, 'cwd parameter is not set.' + if not pathlib.Path(cwd).is_dir(): + return False, 'cwd is not an existing directory' + return True, None + + +def run_windows(cwd: Optional[str]) -> utils.RUN_STATUS: + raise NotImplementedError() + + +def run_linux(cwd: Optional[str]) -> utils.RUN_STATUS: + raise NotImplementedError() + + +def run_mac(cwd: str) -> utils.RUN_STATUS: + terminal_type = 'iTerm' + apps_path = pathlib.Path('/Applications') + iterm_dir_pattern = '*[iI][tT]erm*' + results = list(apps_path.glob(iterm_dir_pattern)) + if not results: + terminal_type = 'Terminal' + + utils.run(f'open -a {terminal_type} {cwd}') + + return True, 'Opened terminal successfully' + + +def run_plugin(cwd: Optional[str]) -> utils.RUN_STATUS: + is_startable, err = check_plugin(cwd) + if not is_startable: + return False, err + + assert isinstance(cwd, str) + + platform = utils.get_platform() + if platform == 'windows': + return run_windows(cwd) + elif platform == 'linux': + return run_linux(cwd) + elif platform == 'mac': + return run_mac(cwd) diff --git a/example/example_ktamir/.comeback b/example/example_ktamir/.comeback new file mode 100644 index 0000000..8e85959 --- /dev/null +++ b/example/example_ktamir/.comeback @@ -0,0 +1,2 @@ +terminal: + cwd: /