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.
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
listtakes{}and returnspath,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, andwriter(ready,needsApprovalorunavailable).toggletakesentry(an id fromlist) orhost(a host name on one line) and an optionalenabled; withoutenabledthe entry flips. Turning an entry off comments it out.addtakesaddress(IPv4 or IPv6),hosts(or onehost), optionalcomment,group(a group id; the end of the file when left out) andenabled.edittakesentryorhostand any ofaddress,hosts,commentandenabled.deletetakesentryorhost.applytakesprofile(an id or a name) and optionalenabled(defaulttrue). Turning a profile on adds or refreshes its marked block; turning it off comments the block out."remove": truedeletes the block.plantakesedits, a list of the changes above, each with anopoftoggle,add,edit,deleteorapply, and writes them as one change.These return
base,fingerprint,diff(hunks,added,removed,unified),warnings,written,flushed,backupand, after a write,list.profilestakes{}.profile.savetakesnameand eitherentries(address,hosts,comment),template(emptyorblockDistractions) orgroup(a group id to copy); passidto replace a profile.profile.deletetakesprofile. Saving or deleting a profile never changes the hosts file.backupstakes{}and returnsbackups(id,kind,createdAt,bytes,fingerprint).restoretakesbackup, an id of kindhosts, and plans or writes that version like the operations above.approvetakes{}, asks macOS to start Edith's privileged helper and returnswriter.envtakes an optionalrevealand returnsshell,startupFile,shellAvailable,launchdAvailable,blockPresent,managedandvariables(name,value,sensitive,masked,managed,shell,launchd). Values of names that look like keys, tokens or passwords are masked unlessrevealistrueor Show values of keys and tokens is on.env.settakesnameandvalue.env.unsettakesname. Both returnstartupFile,diff,written,backupandmanaged.