Skip to content

Commit

Permalink
[utils]: feat add windows support
Browse files Browse the repository at this point in the history
fixes #25
  • Loading branch information
Sharparam authored Aug 27, 2023
1 parent 7d9d028 commit 7097548
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 35 deletions.
14 changes: 8 additions & 6 deletions fnl/tangerine/utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ utils[env]
```fennel
:path {
:goto-output (function 1)
:resolve (function 2)
:shortname (function 3)
:source (function 4)
:target (function 5)
:transform-path (function 6)
:wildcard (function 7)
:gsub (function 2)
:match (function 3)
:resolve (function 4)
:shortname (function 5)
:source (function 6)
:target (function 7)
:transform-path (function 8)
:wildcard (function 9)
}
```

Expand Down
4 changes: 3 additions & 1 deletion fnl/tangerine/utils/fs.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

(lambda fs.write [path content]
"writes string of 'content' to 'path'."
(local dir (path:match "(.*/)"))
(local dir (if (= _G.jit.os "Windows")
(path:match "(.*[/\\])")
(path:match "(.*/)")))
(if (= 0 (vim.fn.isdirectory dir))
(vim.fn.mkdir dir :p))
(with-open [file (assert (io.open path :w))]
Expand Down
22 changes: 18 additions & 4 deletions fnl/tangerine/utils/path.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@
;; -------------------- ;;
;; Utils ;;
;; -------------------- ;;
(local windows? (= _G.jit.os "Windows"))

(lambda p.match [path pattern]
"matches 'path' against 'pattern' with support for windows."
(if windows?
(path:match (pattern:gsub "/" "[\\/]"))
(path:match pattern)))

(lambda p.gsub [path pattern repl]
"substitutes 'pattern' in 'path' for 'repl' with support for windows."
(if windows?
(path:gsub (pattern:gsub "/" "[\\/]") repl)
(path:gsub pattern repl)))

(lambda p.shortname [path]
"shortens absolute 'path' for better readability."
(or (path:match ".+/fnl/(.+)")
(path:match ".+/lua/(.+)")
(path:match ".+/(.+/.+)")))
(or (p.match path ".+/fnl/(.+)")
(p.match path ".+/lua/(.+)")
(p.match path ".+/(.+/.+)")))

(lambda p.resolve [path]
"resolves 'path' to POSIX complaint path."
Expand All @@ -36,7 +50,7 @@
path (path:gsub (.. "%." ext1 "$") (.. "." ext2))]
(if (path:find from)
(path:gsub from to)
(path:gsub (.. "/" ext1 "/") (.. "/" ext2 "/")))))
(p.gsub path (.. "/" ext1 "/") (.. "/" ext2 "/")))))

(lambda p.target [path]
"converts fnl:'path' to valid target path."
Expand Down
13 changes: 9 additions & 4 deletions lua/tangerine/utils/fs.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 40 additions & 20 deletions lua/tangerine/utils/path.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7097548

Please sign in to comment.