DEV Community

Mark
Mark

Posted on • Originally published at alchemist.camp

2 2

The .iex.exs file

The .iex.exs file is a "must have" convenience.

You can use it to set aliases, set imports and add define helper functions for every IEx session you run!

Here's what's in my global one:

import_if_available(Ecto.Query)
import_if_available(Ecto.Changeset)

defmodule AC do
  def update(schema, changes) do
    schema
    |> Ecto.Changeset.change(changes)
    |> Repo.update()
  end

  IEx.configure(
    colors: [
      syntax_colors: [
        number: :light_yellow,
        atom: :light_cyan,
        string: :light_black,
        boolean: [:light_blue],
        nil: [:magenta, :bright]
      ],
      ls_directory: :cyan,
      ls_device: :yellow,
      doc_code: :green,
      doc_inline_code: :magenta,
      doc_headings: [:cyan, :underline],
      doc_title: [:cyan, :bright, :underline]
    ],
    default_prompt:
      [
        # ANSI CHA, move cursor to column 1
        "\e[G",
        :light_magenta,
        # plain string
        "🧪 iex",
        ">",
        :white,
        :reset
      ]
      |> IO.ANSI.format()
      |> IO.chardata_to_string()
  )
end

And in this project, my local .iex.exs has:

alias Campsite.{Accounts, Content, Extract, Game, Repo}
alias Accounts.{User, Credential}
alias Content.{Article, Comment, Episode, Podcast}
alias Game.Request

With these in place, every time IEx starts up, commonly used modules are automatically aliased, Ecto queries are easier and there's a nice 🧪 prompt making it clear the terminal is in IEx. 🎉

Request a free email-based Elixir course from Alchemist.Camp

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay