Skip to content
Edith

Docs

Command reference

Hosts & Environment

Hosts & Environment has no command group of its own. Every action on its page and Home card is an operation of the running extension, sent through ed invoke with a JSON payload. Results are JSON on stdout; a refused request prints a JSON error on stderr and exits non-zero.

Terminal
ed invoke hostsEditor list --json '{}'ed invoke hostsEditor toggle --json '{"host":"api.staging.test"}'ed invoke hostsEditor toggle --json '{"host":"api.staging.test","write":true}'ed invoke hostsEditor add --json '{"address":"127.0.0.1","hosts":["shop.test"],"write":true}'ed invoke hostsEditor apply --json '{"profile":"Staging","write":true}'ed invoke hostsEditor env --json '{}'ed invoke hostsEditor env.set --json '{"name":"EDITOR","value":"nvim","write":true}'

Writing

Every operation that changes a file returns the exact unified diff it would write and changes nothing unless the payload has "write": true. Pass the base fingerprint from an earlier reply to refuse the write when the file changed since that diff was made.

A hosts write keeps a backup of the previous file, asks for an administrator through the macOS authorization prompt, writes /etc/hosts through Edith's privileged helper and clears the DNS cache when Clear the DNS cache after writing is on. The helper needs a one-time approval in System Settings > General > Login Items & Extensions; approve starts it. The line that maps localhost to 127.0.0.1 and the other entries macOS needs can never be turned off, changed or deleted.

Environment writes change only the block between # >>> Edith managed environment >>> and # <<< Edith managed environment <<< in the login shell's startup file (~/.zshrc, ~/.bash_profile, ~/.config/fish/config.fish or ~/.profile). They need no administrator and keep a backup of the previous file.

Operations

  • list takes {} and returns path, fingerprint, lines, entries (id, line, enabled, address, family, hosts, comment, group, profile, system), groups (id, title, profile, entries, enabled), profiles (id, name, entries, present, active), unknownLines, warnings, and writer (ready, needsApproval or unavailable).

  • toggle takes entry (an id from list) or host (a host name on one line) and an optional enabled; without enabled the entry flips. Turning an entry off comments it out.

  • add takes address (IPv4 or IPv6), hosts (or one host), optional comment, group (a group id; the end of the file when left out) and enabled.

  • edit takes entry or host and any of address, hosts, comment and enabled.

  • delete takes entry or host.

  • apply takes profile (an id or a name) and optional enabled (default true). Turning a profile on adds or refreshes its marked block; turning it off comments the block out. "remove": true deletes the block.

  • plan takes edits, a list of the changes above, each with an op of toggle, add, edit, delete or apply, and writes them as one change.

  • These return base, fingerprint, diff (hunks, added, removed, unified), warnings, written, flushed, backup and, after a write, list.

  • profiles takes {}. profile.save takes name and either entries (address, hosts, comment), template (empty or blockDistractions) or group (a group id to copy); pass id to replace a profile. profile.delete takes profile. Saving or deleting a profile never changes the hosts file.

  • backups takes {} and returns backups (id, kind, createdAt, bytes, fingerprint). restore takes backup, an id of kind hosts, and plans or writes that version like the operations above.

  • approve takes {}, asks macOS to start Edith's privileged helper and returns writer.

  • env takes an optional reveal and returns shell, startupFile, shellAvailable, launchdAvailable, blockPresent, managed and variables (name, value, sensitive, masked, managed, shell, launchd). Values of names that look like keys, tokens or passwords are masked unless reveal is true or Show values of keys and tokens is on.

  • env.set takes name and value. env.unset takes name. Both return startupFile, diff, written, backup and managed.

  • ed invoke

  • All command groups