on 4ff1e79 help sign in
urbit.org/docs/using/shell.md
277 lines 6.8 kB history raw
1---
2navhome: /docs
3next: true
4sort: 5
5title: Shell (:dojo)
6---
8# Shell (`:dojo`)
10<div class="row">
11<div class="col-md-8">
13The `:dojo` is the place to quickly experiment with Urbit. On
14the surface the `:dojo` is just a Hoon REPL. On the inside, the
15`:dojo` is a system for operating on and transforming data in
16Urbit.
18</div>
19</div>
21## Quickstart
23Evaluate a hoon expression:
25 ~your-urbit:dojo> (add 2 2)
26 ~your-urbit:dojo> %+ add 2 2
28Tall form Hoon may require multiple lines:
30 ~your-urbit:dojo> %+ add
31 ~your-urbit:dojo< 2
32 ~your-urbit:dojo< 2
34Use `=var` to save a shell variable:
36 ~your-urbit:dojo> =foo (add 2 2)
38Use `=dir` to set the current working directory:
40 ~your-urbit:dojo> =dir %/web
42Generators (files in `/gen`) are run with `+`:
44 ~your-urbit:dojo> +hello 'world'
46Save output to a file in `%clay` with `*`:
48 ~your-urbit:dojo> *some/file/path/hoon 'hello world'
50Run system commands from `:hood`, like `reload`, using `|`:
52 ~your-urbit:dojo> |reload %eyre
55### Generators
57**`+cat`** - Similar to Unix `cat`. Accepts a path.
59 ~your-urbit:dojo> +cat %/web/md
60 ~your-urbit:dojo> +cat /~talsur-todres/home/2/web/notes/md
62**`+curl`** - Similar to Unix `curl`. Accepts a `tape`.
64 ~your-urbit:dojo> +curl "http://nyt.com"
66**`+hello`** - Just prints the argument. Accepts a `@ta`.
68 ~your-urbit:dojo> +hello 'mars'
70**`+ls`** - Similar to Unix `ls`. Accepts a path.
72 ~your-urbit:dojo> +ls %/web
73 ~your-urbit:dojo> +ls /~talsur-todres/home/2/web/notes
75**`+moon`** - Generate a random moon from a planet. No arguments.
77**`+solid`** - Compile the current state of the kernel and output a noun. Usually downloaded to a file in unix. No arguments.
79 ~your-urbit:dojo> .urbit/pill +solid
81**`+ticket`** - Generate a ticket for an Urbit plot. Takes an Urbit name (`@p`).
83 ~your-urbit:dojo> +ticket ~talsur-todres-your-urbit
85**`+tree`** - Generate a recursive directory listing. Takes a path.
87 ~your-urbit:dojo> +tree %/web
89### Hood
91The hood is the system daemon. See `gen/hood` and `app/hood`.
93**`|hi`** - Sends a direct message. Sort of like Unix `write`. Accepts an urbit name (`@p`) and a string (`cord`).
95 ~your-urbit:dojo> |hi ~doznec 'you there?'
97**`|link`** / **`|unlink`** - Link / unlink a remote app. Accepts an Urbit name and an app name.
99 ~your-urbit:dojo> |link ~talsur-todres %octo
101**`|mass`** - Prints the current memory usage of all the kernel modules. No arguments.
103**`|reload`** - Reloads a kernel module (vane) from source. Accepts any number of vane names.
105 ~your-urbit:dojo> |reload %clay %eyre
107**`|reset`** - Reloads `hoon.hoon`. No arguments.
109**`|start`** - Starts an app. Accepts an app name.
111 ~your-urbit:dojo> |start %curl
113## Manual
115<h3 class="first child">Sources and sinks</h3>
117A dojo command is either a source or a sink. A source is just something that can be printed to your console or the result of some computation. A sink is an *effect*: a change to the filesystem, a network message, a change to your environment, or typed message to an app.
119Sources can be chained together, but we can only produce one effect per command.
121### Sinks
123#### `=` - Set variable
125Set any envronment variable:
127 ~your-urbit:dojo> =foo 42
128 ~your-urbit:dojo> (add 2 foo)
130 44
132(There are a few special variables that the dojo expects. See below.)
134#### `:` - Send to app
136`:app` goes to a local `app`, `:~ship/app` goes to the `app` on `~ship`.
138Send a `helm-hi` message to `hood`:
140 ~your-urbit:dojo> :hood &helm-hi 'hi'
142App usually expect marked data, so `&` is often used here.
144#### `*` - Save in `%clay`
146Save a new `md` file in `web`:
148 ~your-urbit:dojo> *%/web/foo/md '# hello'
150The last component of the path is expected to be the mark (or mime type).
152#### `.` - Download to Unix
154Download a noun to Unix with `.`:
156 ~your-urbit:dojo> .foo/bar/baz (add 2 2)
158Which creates a file at `pier/.urb/put/foo/bar.baz`.
160This is very often used with `+solid`:
162 ~your-urbit:dojo> .urbit/pill +solid
164Which outputs a new `urbit.pill` to `pier/.urb/put/urbit.pill`
166### Sources
168#### `&` - Mark conversion
170Convert between marks using `&`:
172 ~your-urbit:dojo> &html &md '# hello'
173 :: produces
174 '<html><head></head><body><div><h1 id="-hello">hello</h1></div></body></html>'
176#### `_` - Run a function
178Use `_` to run a gate (or function):
180 :: assign an arbitrary function and pass data to it
181 ~your-urbit:dojo> _|=({a/@} (mul a 3)) 3
182 :: produces
183 9
184 :: assign an arbitrary function to get the status code from an http request
185 ~your-urbit:dojo> _|=({p/@ud q/* r/*} p) +http://google.com
186 :: produces
187 301
189#### `+` `-` - HTTP requests
191`+http[s]://example.com` - sends a GET request
193`+http[s]://example.com &json [%s 'hi']` - sends a POST request with the JSON `"hi"` in the body.
195`-http[s]://example.com &json [%s 'hi']` - sends a PUT request with the JSON `"hi"` in the body.
197Note that the first of these is a source while the last two are
198sinks.
200#### `+` - Generators
202Generators are simple hoon scripts loaded from the filesystem. They live in `gen/`.
204Create a random moon (from any planet):
206 ~your-urbit:dojo> +moon
207 :: produces
208 "moon: ~docsun-tamtem-your-urbit; ticket: ~bartug-hodbyr-fognum-ralmud"
210### Variables
212You can use `=` to set an environment variable in `:dojo`, but there are a few reserved names that have special uses.
214#### `dir`
216Current working `%clay` desk and revision. Read / write.
218**Examples:**
220 ~your-urbit:dojo> =dir %/web
221 ~your-urbit:dojo> +ls %
223 404/hoon docs/ dojo/hoon lib/ listen/hoon md static/md talk/ tree/main/
225#### `lib`
227Current set of libraries (`/lib`) in your environment. Can also be set with `/+`. Read / write.
229**Examples:**
231 ~your-urbit:dojo> =lib ~[[%react ~]]
232 ~your-urbit:dojo> :: this also works:
233 ~your-urbit:dojo> /+ react
234 ~your-urbit:dojo> :: now we can use arms from lib/react.hoon
235 ~your-urbit:dojo> (react-vale:react %div)
237#### `sur`
239Current set of structures (`/sur`) in your environment. Can also be set with `/-`. Read / write.
241**Examples:**
243 ~your-urbit:dojo> =sur ~[[%sole ~]]
244 ~your-urbit:dojo> :: this also works:
245 ~your-urbit:dojo> /- sole
246 ~your-urbit:dojo> :: now we can use arms in sur/sole.hoon
247 ~your-urbit:dojo> `sole-effect:sole`[%bel ~]
249#### `now`
251The current (128-bit `@da`) time. Read-only.
253**Example:**
255 ~your-urbit:dojo> now
256 :: produces
257 ~2016.3.21..21.10.57..429a
259#### `our`
261The current urbit plot. Read-only.
263**Example:**
265 ~your-urbit:dojo> our
266 :: produces
267 ~your-urbit
269#### `eny`
271256 bits of entropy. Read-only.
273**Example:**
275 ~your-urbit:dojo> eny
276 :: produces
277 0v1o.m2vio.j5ieb.7tq84.5kcnp.gjn04.9gl2e.tkj5v.0oqk3.iugk8.rhu6o