Skip to content

Commit 52f36a4

Browse files
committed
Fix ls IEx helper to render file types correctly for all paths
1 parent 92ac9ab commit 52f36a4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/iex/lib/iex/helpers.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,11 @@ defmodule IEx.Helpers do
312312
If `path` points to a file, prints its full path.
313313
"""
314314
def ls(path // ".") do
315-
case File.ls(expand_home(path)) do
315+
path = expand_home(path)
316+
case File.ls(path) do
316317
{ :ok, items } ->
317318
sorted_items = Enum.sort(items)
318-
ls_print(sorted_items)
319+
ls_print(path, sorted_items)
319320

320321
{ :error, :enoent } ->
321322
IO.puts IO.ANSI.escape("%{red}No such file or directory #{path}")
@@ -331,25 +332,26 @@ defmodule IEx.Helpers do
331332

332333
defp expand_home(other), do: other
333334

334-
defp ls_print([]) do
335+
defp ls_print(_, []) do
335336
:ok
336337
end
337338

338-
defp ls_print(list) do
339+
defp ls_print(path, list) do
339340
# print items in multiple columns (2 columns in the worst case)
340341
lengths = Enum.map(list, String.length(&1))
341342
maxlen = maxlength(lengths)
342343
width = min(maxlen, 30) + 5
343-
ls_print(list, width)
344+
ls_print(path, list, width)
344345
end
345346

346-
defp ls_print(list, width) do
347+
defp ls_print(path, list, width) do
347348
Enum.reduce(list, 0, fn(item, len) ->
348349
if len >= 80 do
349350
IO.puts ""
350351
len = 0
351352
end
352-
IO.write format_item(item, iolist_to_binary(:io_lib.format('~-*ts', [width, item])))
353+
IO.write format_item(Path.join(path, item),
354+
iolist_to_binary(:io_lib.format('~-*ts', [width, item])))
353355
len+width
354356
end)
355357
IO.puts ""

0 commit comments

Comments
 (0)