Skip to content

Commit

Permalink
add regex path search
Browse files Browse the repository at this point in the history
  • Loading branch information
vans163 committed Aug 15, 2020
1 parent 4b97878 commit 41a9e1a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Prerequisite
-----
On Linux you need to install inotify-tools.

```
-m: 1: inotifywait: not found
```

Use
---
Expand Down Expand Up @@ -45,3 +48,16 @@ Compiling relx
1>
```

Custom extensions, thanks abxy.
Regex matches are supported, "$" is suffixed automatically, thanks xuchaoqian.
```
re:run(<<"file_name.erl_ab">>, <<ExtMatch/binary, "$">>)
```

```
To extend the list add an option to your rebar.config like so:
{extra_extensions, [".alp", ".hterl", ".erl(.*?)"]}.
```
7 changes: 6 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
[{<<"enotify">>,{pkg,<<"enotify">>,<<"0.1.0">>},0}].
{"1.1.0",
[{<<"enotify">>,{pkg,<<"enotify">>,<<"0.1.0">>},0}]}.
[
{pkg_hash,[
{<<"enotify">>, <<"F6BF33AA7BC4789D953087E48C6ADBC6D9682B6D67E4BC353C2FDB96C5AC5595">>}]}
].
2 changes: 1 addition & 1 deletion src/rebar3_auto.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application,rebar3_auto,
[{description,"Rebar3 plugin for auto compiling on changes"},
{vsn,"0.3.2"},
{vsn,"0.3.3"},
{registered,[]},
{applications,[kernel,stdlib,enotify]},
{env,[]},
Expand Down
29 changes: 23 additions & 6 deletions src/rebar3_auto.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
,do/1
,format_error/1]).

-export([auto/0, flush/0]).
-export([auto/1, flush/0]).

-define(PROVIDER, auto).
-define(DEPS, [compile]).
Expand Down Expand Up @@ -70,15 +70,20 @@ format_error(Reason) ->
do(State) ->
spawn(fun() ->
listen_on_project_apps(State),
?MODULE:auto()
Extensions = get_extensions(State),
?MODULE:auto(Extensions)
end),
State1 = remove_from_plugin_paths(State),
rebar_prv_shell:do(State1).

-define(VALID_EXTENSIONS,[<<".erl">>, <<".hrl">>, <<".src">>, <<".lfe">>, <<".config">>, <<".lock">>,
-define(VALID_EXTENSIONS_DEFAULT,[<<".erl">>, <<".hrl">>, <<".src">>, <<".lfe">>, <<".config">>, <<".lock">>,
<<".c">>, <<".cpp">>, <<".h">>, <<".hpp">>, <<".cc">>]).

auto() ->
get_extensions(State) ->
ExtraExtensions = rebar_state:get(State, extra_extensions, []),
[unicode:characters_to_binary(Ext) || Ext <- ExtraExtensions] ++ ?VALID_EXTENSIONS_DEFAULT.

auto(Extensions) ->
case whereis(rebar_agent) of
undefined ->
timer:sleep(100);
Expand All @@ -87,7 +92,19 @@ auto() ->
receive
{ChangedFile, _Events} ->
Ext = filename:extension(unicode:characters_to_binary(ChangedFile)),
IsValid = lists:member(Ext, ?VALID_EXTENSIONS),
IsValid = lists:any(
fun(ValidExt) ->
RE = <<ValidExt/binary, "$">>,
Result = re:run(Ext, RE),
case Result of
{match, _Captured} -> true;
match -> true;
nomatch -> false;
{error, _ErrType} -> false
end
end,
Extensions
),
case IsValid of
false -> pass;
true ->
Expand All @@ -101,7 +118,7 @@ auto() ->
end

end,
?MODULE:auto().
?MODULE:auto(Extensions).

flush() ->
receive
Expand Down

0 comments on commit 41a9e1a

Please sign in to comment.