-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcodex-cli-project.el
More file actions
36 lines (30 loc) · 1.24 KB
/
codex-cli-project.el
File metadata and controls
36 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;;; codex-cli-project.el --- Project root discovery for codex-cli -*- lexical-binding: t; -*-
;; Author: Benn <bennmsg@gmail.com>
;; Maintainer: Benn <bennmsg@gmail.com>
;; SPDX-License-Identifier: MIT
;; Keywords: tools convenience codex codex-cli
;; URL: https://github.com/bennfocus/codex-cli.el
;;; Commentary:
;; Project root discovery via `project.el` and relative path helpers for
;; codex-cli.
;;; Code:
(require 'project)
(defun codex-cli-project-root ()
"Return the project root directory or signal an error.
Falls back to `default-directory' when buffer is not visiting a file."
(let* ((current-dir (or (and buffer-file-name
(file-name-directory buffer-file-name))
default-directory))
(project (project-current nil current-dir)))
(if project
(project-root project)
(error "No project found for directory: %s" current-dir))))
(defun codex-cli-relpath (path)
"Return PATH relative to the project root.
If PATH is not under the project root, return the absolute path."
(let ((root (codex-cli-project-root)))
(if (string-prefix-p root path)
(file-relative-name path root)
path)))
(provide 'codex-cli-project)
;;; codex-cli-project.el ends here