Skip to content

Commit

Permalink
Merge pull request #14 from psibi/handle-all-justfiles
Browse files Browse the repository at this point in the history
Handle all justfiles
  • Loading branch information
psibi authored Mar 11, 2022
2 parents 73cb3a8 + 6654dc4 commit b24b4ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
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

0 comments on commit b24b4ec

Please sign in to comment.