Skip to content

Commit 8010e44

Browse files
author
José Valim
committed
Bring the multiple .iex.exs functionality
1 parent 8b203a8 commit 8010e44

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
* [String] Deprecate `:global` option in `String.split/3` in favor of `parts: :infinity`
4242

4343
* Backwards incompatible changes
44-
* [IEx] IEx no longer loads an `.iex.exs` file at the current path. Instead, IEx should be configured via the new Mix config
4544
* [ExUnit] `ExUnit.Test` and `ExUnit.TestCase` has been converted to structs
4645
* [ExUnit] The test and callback context has been converted to maps
4746
* [Kernel] `File.Stat`, `HashDict`, `HashSet`, `Inspect.Opts`, `Macro.Env`, `Range`, `Regex` and `Version.Requirement` have been converted to structs. This means `is_record/2` checks will no longer work, instead, you can pattern match on them using `%Range{}` and similar

bin/iex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ $# -gt 0 ] && ([ "$1" = "--help" ] || [ "$1" = "-h" ]); then
1818
--detached Starts the Erlang VM detached from console
1919
--gen-debug Turns on default debugging for all GenServers
2020
--remsh \"name\" Connects to a node using a remote shell
21-
--dot-iex \"path\" Overrides default ~/.iex.exs file and uses path instead;
21+
--dot-iex \"path\" Overrides default .iex.exs file and uses path instead;
2222
path can be empty, then no file will be loaded
2323
2424
** Options marked with (*) can be given more than once

lib/iex/lib/iex.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ defmodule IEx do
120120
Connecting an Elixir shell to a remote node without Elixir is
121121
**not** supported.
122122
123-
## The ~/.iex.exs file
123+
## The .iex.exs file
124124
125-
When starting IEx, it will look for a global configuration file
126-
(located at `~/.iex.exs`) and load it if available. The code in the
127-
chosen .iex file will be evaluated in the shell's context. So, for
128-
instance, any modules that are loaded or variables that are bound
129-
in the .iex file will be available in the shell after it has booted.
125+
When starting IEx, it will look for a local `.iex.exs` file (located in the current
126+
working directory), then a global one (located at `~/.iex.exs`) and will load the
127+
first one it finds (if any). The code in the chosen .iex file will be
128+
evaluated in the shell's context. So, for instance, any modules that are
129+
loaded or variables that are bound in the .iex file will be available in the
130+
shell after it has booted.
130131
131-
Sample contents of a .iex file:
132+
Sample contents of a local .iex file:
132133
133134
# source another `.iex` file
134135
import_file "~/.iex.exs"
@@ -140,7 +141,7 @@ defmodule IEx do
140141
value = 13
141142
142143
Running the shell in the directory where the above .iex file is located
143-
results in
144+
results in:
144145
145146
$ iex
146147
Erlang 17 [...]

lib/iex/lib/iex/evaluator.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ defmodule IEx.Evaluator do
3939
Returns the new config.
4040
"""
4141
def load_dot_iex(config, path \\ nil) do
42-
path = path || "~/.iex.exs"
43-
44-
if File.regular?(path) do
45-
eval_dot_iex(config, path)
42+
candidates = if path do
43+
[path]
4644
else
45+
Enum.map [".iex.exs", "~/.iex.exs"], &Path.expand/1
46+
end
47+
48+
path = Enum.find candidates, &File.regular?/1
49+
50+
if nil?(path) do
4751
config
52+
else
53+
eval_dot_iex(config, path)
4854
end
4955
end
5056

0 commit comments

Comments
 (0)