diff --git a/gcalcli/cli.py b/gcalcli/cli.py index 5f7ad1d..1ef51c5 100755 --- a/gcalcli/cli.py +++ b/gcalcli/cli.py @@ -40,6 +40,8 @@ from argparse import ArgumentTypeError from collections import namedtuple +import shopen + from . import config, env, utils from .argparsers import get_argument_parser, handle_unparsed from .exceptions import GcalcliError @@ -347,7 +349,7 @@ def main(): config_filepath.parent.mkdir(parents=True, exist_ok=True) with open(config_filepath, 'w') as f: f.write(EMPTY_CONFIG_TOML) - utils.launch_editor(config_filepath) + shopen.open(config_filepath, 'edit') elif parsed_args.command == 'util': if parsed_args.subcommand == 'config-schema': diff --git a/gcalcli/utils.py b/gcalcli/utils.py index 2d83c56..1959b6f 100644 --- a/gcalcli/utils.py +++ b/gcalcli/utils.py @@ -2,11 +2,9 @@ from collections import OrderedDict import json import locale -import os import pathlib import pickle import re -import subprocess import time from datetime import datetime, timedelta from typing import Any, Tuple @@ -207,26 +205,6 @@ def localize_datetime(dt): return dt.astimezone(tzlocal()) -def launch_editor(path: str | os.PathLike): - if hasattr(os, 'startfile'): - os.startfile(path, 'edit') - return - for editor in ( - 'editor', - os.environ.get('EDITOR', None), - 'xdg-open', - 'open', - ): - if not editor: - continue - try: - subprocess.call((editor, path)) - return - except OSError: - pass - raise OSError(f'No editor/launcher detected on your system to edit {path}') - - def shorten_path(path: pathlib.Path) -> pathlib.Path: """Try to shorten path using special characters like ~. diff --git a/pyproject.toml b/pyproject.toml index f70a63a..83e8219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ "platformdirs", "pydantic", "python-dateutil", + "shopen >= 0.2.2", "tomli; python_version < '3.11'", "truststore", ]