File tree Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Expand file tree Collapse file tree 3 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,15 @@ defmodule Mix.Local do
1313 Path . join ( Mix.Utils . mix_home , "archives" )
1414 end
1515
16+ @ doc """
17+ The path for local escripts.
18+
19+ Check `mix escript` for info.
20+ """
21+ def escripts_path do
22+ Path . join ( Mix.Utils . mix_home , "escripts" )
23+ end
24+
1625 @ doc """
1726 Appends archives paths into Erlang code path.
1827 """
Original file line number Diff line number Diff line change 11defmodule Mix.Tasks.Archive do
22 use Mix.Task
33
4- @ shortdoc "Lists all archives"
4+ @ shortdoc "Lists installed archives"
55
66 @ moduledoc """
77 Lists all installed archives.
88
99 Archives are typically installed at `~/.mix/archives`
10- although the installation path can be customize by
10+ although the installation path can be customized by
1111 setting the `MIX_ARCHIVES` environment variable.
1212
1313 Since archives are specific to Elixir versions, it is
Original file line number Diff line number Diff line change 1+ defmodule Mix.Tasks.Escript do
2+ use Mix.Task
3+
4+ @ shortdoc "List installed escripts."
5+
6+ @ moduledoc ~S"""
7+ Lists all installed escripts.
8+
9+ Escripts are installed at `~/.mix/escripts`. Add that path to your `PATH` environment variable
10+ to be able to run installed escripts from any directory.
11+ """
12+
13+ use Bitwise
14+
15+ @ spec run ( OptionParser . argv ) :: :ok
16+ def run ( _ ) do
17+ escripts_path = Mix.Local . escripts_path
18+
19+ escripts =
20+ escripts_path
21+ |> list_dir
22+ |> Enum . filter ( fn filename -> executable? ( Path . join ( [ escripts_path , filename ] ) ) end )
23+
24+ if escripts == [ ] do
25+ Mix . shell . info "No escripts currently installed."
26+ else
27+ Enum . each escripts , fn filename ->
28+ Mix . shell . info "* #{ filename } "
29+ end
30+
31+ Mix . shell . info "Escripts installed at: #{ escripts_path } "
32+ end
33+ end
34+
35+ defp list_dir ( path ) do
36+ case File . ls ( path ) do
37+ { :ok , list } -> list
38+ _ -> [ ]
39+ end
40+ end
41+
42+ defp executable? ( path ) do
43+ owner_exec_bit = 0o00100
44+ group_exec_bit = 0o00010
45+ other_exec_bit = 0o00001
46+ ( File . stat! ( path ) . mode &&& ( owner_exec_bit ||| group_exec_bit ||| other_exec_bit ) ) != 0
47+ end
48+ end
You can’t perform that action at this time.
0 commit comments