Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal support for mac with example .comeback file #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
50 changes: 50 additions & 0 deletions comeback/plugins/terminal/main.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions example/example_ktamir/.comeback
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
terminal:
cwd: /