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

Handle all justfiles #14

Merged
merged 2 commits into from
Mar 11, 2022
Merged
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
8 changes: 7 additions & 1 deletion Changelog.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* 0.7 (Unreleased)

- Finds all types of justfiles now and makes it compatible with the
~just~ program. Earlier it used to just working with ~justfile~ and
~.justfile.

* 0.6

- Make the directory parsing smart. Now invoking justl from any
Expand All @@ -15,7 +21,7 @@
buffer.
- Fix bug when process execution itself throws error.
- Migrate from the deprecated ~define-transient-command~
- Fix justl process when you pass transient argument for ~--color~~
- Fix justl process when you pass transient argument for ~--color~

* 0.4

Expand Down
48 changes: 30 additions & 18 deletions justl.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ NAME is the buffer name."
(defconst justl--output-process-buffer "*just*"
"Just output process buffer name.")

(defconst justl--justfile-regex "[Jj][Uu][sS][tT][fF][iI][lL][eE]"
"Justfile name.")

(defun justl--is-variable-p (str)
"Check if string STR is a just variable."
(s-contains? ":=" str))
Expand All @@ -160,18 +163,33 @@ NAME is the buffer name."
If this is NIL, it means that no justfiles was found. In any
other cases, it's a known path.")

(defun justl--find-any-justfiles (dir filename)
"Find just FILENAME inside a sub-directory DIR or a parent directory.
(defun justl--traverse-upwards (fn &optional path)
"Traverse up as long as FN return nil, starting at PATH.

Variant of f.el's 'f-traverse-upwards but returns justfiles."
(unless path
(setq path default-directory))
(when (f-relative? path)
(setq path (f-expand path)))
(let ((result (funcall fn path)))
(if result
result
(unless (f-root? path)
(justl--traverse-upwards fn (f-parent path))))))

(defun justl--find-any-justfiles (dir)
"Find justfiles inside a sub-directory DIR or a parent directory.

Returns the absolute path if FILENAME exists or nil if no path
Returns the absolute path if file exists or nil if no path
was found."
(let ((justfile-dir (f-traverse-upwards
(lambda (path)
(f-exists? (f-expand filename path)))
dir)))
(if justfile-dir
(f-expand filename justfile-dir)
(let ((justfile-paths (directory-files-recursively dir filename)))
(let ((case-fold-search t)
(justfiles (justl--traverse-upwards
(lambda (path)
(directory-files path t justl--justfile-regex))
dir)))
(if justfiles
(car justfiles)
(let ((justfile-paths (directory-files-recursively dir "justfile")))
(if justfile-paths
(car justfile-paths)
nil)))))
Expand All @@ -181,17 +199,11 @@ was found."

DIR represents the directory where search will be carried out.
It searches either for the filename justfile or .justfile"
(let ((justfile-path (justl--find-any-justfiles dir "justfile")))
(let ((justfile-path (justl--find-any-justfiles dir)))
(if justfile-path
(progn
(setq justl--justfile justfile-path)
justfile-path)
(let ((dot-justfile-path (justl--find-any-justfiles dir ".justfile")))
(if dot-justfile-path
(progn
(setq justl--justfile dot-justfile-path)
dot-justfile-path)
nil)))))
justfile-path))))

(defun justl--get-recipe-name (str)
"Compute the recipe name from the string STR."
Expand Down