<commit_before>defmodule Mix.Tasks.Escript do
  use Mix.Task

  @shortdoc "List installed escripts."

  @moduledoc ~S"""
  Lists all installed escripts.

  Escripts are installed at `~/.mix/escripts`. Add that path to your `PATH` environment variable
  to be able to run installed escripts from any directory.
  """

  use Bitwise

  @spec run(OptionParser.argv) :: :ok
  def run(_) do
    escripts_path = Mix.Local.escripts_path

    escripts =
      escripts_path
      |> list_dir
      |> Enum.filter(fn filename -> executable?(Path.join([escripts_path, filename])) end)

    if escripts == [] do
      Mix.shell.info "No escripts currently installed."
    else
      Enum.each escripts, fn filename ->
        Mix.shell.info "* #{filename}"
      end

      Mix.shell.info "Escripts installed at: #{escripts_path}"
    end
  end

  defp list_dir(path) do
    case File.ls(path) do
      {:ok, list} -> list
      _ -> []
    end
  end

  defp executable?(path) do
    owner_exec_bit = 0o00100
    group_exec_bit = 0o00010
    other_exec_bit = 0o00001
    (File.stat!(path).mode &&& (owner_exec_bit ||| group_exec_bit ||| other_exec_bit)) != 0
  end
end<commit_msg>Check the file type when building the list of installed escripts<commit_after>defmodule Mix.Tasks.Escript do
  use Mix.Task

  @shortdoc "List installed escripts."

  @moduledoc ~S"""
  Lists all installed escripts.

  Escripts are installed at `~/.mix/escripts`. Add that path to your `PATH` environment variable
  to be able to run installed escripts from any directory.
  """

  use Bitwise

  @spec run(OptionParser.argv) :: :ok
  def run(_) do
    escripts_path = Mix.Local.escripts_path

    escripts =
      escripts_path
      |> list_dir
      |> Enum.filter(fn filename -> executable?(Path.join([escripts_path, filename])) end)

    if escripts == [] do
      Mix.shell.info "No escripts currently installed."
    else
      Enum.each escripts, fn filename ->
        Mix.shell.info "* #{filename}"
      end

      Mix.shell.info "Escripts installed at: #{escripts_path}"
    end
  end

  defp list_dir(path) do
    case File.ls(path) do
      {:ok, list} -> list
      _ -> []
    end
  end

  defp executable?(path) do
    owner_exec_bit = 0o00100
    group_exec_bit = 0o00010
    other_exec_bit = 0o00001
    stat = File.stat!(path)

    (stat.mode &&& (owner_exec_bit ||| group_exec_bit ||| other_exec_bit)) != 0
    and stat.type == :regular
  end
end
{'fraction_non_alphanumeric': 0.1087848932676519, 'fraction_numerical': 0.015599343185550082, 'mean_word_length': 2.8438485804416405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '950109', 'n_tokens_mistral': 869, 'n_tokens_neox': 811, 'n_words': 226}