Skip to content

Commit 41a9e1a

Browse files
committed
add regex path search
1 parent 4b97878 commit 41a9e1a

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Prerequisite
77
-----
88
On Linux you need to install inotify-tools.
99

10+
```
11+
-m: 1: inotifywait: not found
12+
```
1013

1114
Use
1215
---
@@ -45,3 +48,16 @@ Compiling relx
4548
4649
1>
4750
```
51+
52+
Custom extensions, thanks abxy.
53+
Regex matches are supported, "$" is suffixed automatically, thanks xuchaoqian.
54+
```
55+
re:run(<<"file_name.erl_ab">>, <<ExtMatch/binary, "$">>)
56+
```
57+
58+
```
59+
To extend the list add an option to your rebar.config like so:
60+
61+
{extra_extensions, [".alp", ".hterl", ".erl(.*?)"]}.
62+
63+
```

rebar.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
[{<<"enotify">>,{pkg,<<"enotify">>,<<"0.1.0">>},0}].
1+
{"1.1.0",
2+
[{<<"enotify">>,{pkg,<<"enotify">>,<<"0.1.0">>},0}]}.
3+
[
4+
{pkg_hash,[
5+
{<<"enotify">>, <<"F6BF33AA7BC4789D953087E48C6ADBC6D9682B6D67E4BC353C2FDB96C5AC5595">>}]}
6+
].

src/rebar3_auto.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application,rebar3_auto,
22
[{description,"Rebar3 plugin for auto compiling on changes"},
3-
{vsn,"0.3.2"},
3+
{vsn,"0.3.3"},
44
{registered,[]},
55
{applications,[kernel,stdlib,enotify]},
66
{env,[]},

src/rebar3_auto.erl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
,do/1
2121
,format_error/1]).
2222

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

2525
-define(PROVIDER, auto).
2626
-define(DEPS, [compile]).
@@ -70,15 +70,20 @@ format_error(Reason) ->
7070
do(State) ->
7171
spawn(fun() ->
7272
listen_on_project_apps(State),
73-
?MODULE:auto()
73+
Extensions = get_extensions(State),
74+
?MODULE:auto(Extensions)
7475
end),
7576
State1 = remove_from_plugin_paths(State),
7677
rebar_prv_shell:do(State1).
7778

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

81-
auto() ->
82+
get_extensions(State) ->
83+
ExtraExtensions = rebar_state:get(State, extra_extensions, []),
84+
[unicode:characters_to_binary(Ext) || Ext <- ExtraExtensions] ++ ?VALID_EXTENSIONS_DEFAULT.
85+
86+
auto(Extensions) ->
8287
case whereis(rebar_agent) of
8388
undefined ->
8489
timer:sleep(100);
@@ -87,7 +92,19 @@ auto() ->
8792
receive
8893
{ChangedFile, _Events} ->
8994
Ext = filename:extension(unicode:characters_to_binary(ChangedFile)),
90-
IsValid = lists:member(Ext, ?VALID_EXTENSIONS),
95+
IsValid = lists:any(
96+
fun(ValidExt) ->
97+
RE = <<ValidExt/binary, "$">>,
98+
Result = re:run(Ext, RE),
99+
case Result of
100+
{match, _Captured} -> true;
101+
match -> true;
102+
nomatch -> false;
103+
{error, _ErrType} -> false
104+
end
105+
end,
106+
Extensions
107+
),
91108
case IsValid of
92109
false -> pass;
93110
true ->
@@ -101,7 +118,7 @@ auto() ->
101118
end
102119

103120
end,
104-
?MODULE:auto().
121+
?MODULE:auto(Extensions).
105122

106123
flush() ->
107124
receive

0 commit comments

Comments
 (0)