about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pyproject.toml2
-rw-r--r--src/git/__init__.py14
-rw-r--r--src/term/link.py9
3 files changed, 24 insertions, 1 deletions
diff --git a/pyproject.toml b/pyproject.toml
index e0ff2f4..3bf7f69 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -62,7 +62,7 @@ max-line-length = 120
 length-sort = true
 length-sort-straight = true
 combine-as-imports = true
-known-first-party = ["rbx_nomad"]
+known-first-party = ["rbx_nomad", "term", "git"]
 
 [project.scripts]
 gha_billing = "cli.gha_billing:cli"
diff --git a/src/git/__init__.py b/src/git/__init__.py
new file mode 100644
index 0000000..319fea2
--- /dev/null
+++ b/src/git/__init__.py
@@ -0,0 +1,14 @@
+from subprocess import CalledProcessError, check_output
+
+
+def root() -> str:
+    try:
+        root = check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
+        return root
+    except CalledProcessError as err:
+        raise OSError("Current working directory is not a git repository") from err
+
+
+def repository_name() -> str:
+    repo_path = root()
+    return repo_path.split("/")[-1]
diff --git a/src/term/link.py b/src/term/link.py
new file mode 100644
index 0000000..cd75b16
--- /dev/null
+++ b/src/term/link.py
@@ -0,0 +1,9 @@
+def link(text: str, url: str) -> str:
+    """Link returns a formatted string that represents a hyperlink.
+    The hyperlink is created using the escape sequence for terminal emulators.
+    The text parameter represents the visible text of the hyperlink,
+    and the url parameter represents the URL that the hyperlink points to.
+For more information on the escape sequence, refer to:
+    https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence
+    """
+    return f""\x1b]8;;{url}\x07{text}\x1b]8;;\x07\u001b[0m""