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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay