A Plan 9 Newbie's Guide
A Plan 9 Newbie's Guide
A Plan 9 Newbie's Guide
Michael A. Covington !
for
Coraid, Inc.
2008 July 10
1.
Introduction
put
save to disk.
rune
snarf
sweep
zerox
2.
When you log on to Plan 9, you are in (text) console mode, but normally your
profile, in file /usr/username/lib/profile, will immediately launch rio, the
windowing system (which replaces an earlier windowing system called 8).
Rio tends to baffle newcomers because its initial display is a blank gray screen
(Figure 1).
-4To make things start happening, right-click anywhere on the gray surface and
choose New (Figure 2). Release the right mouse button, then press it again and
drag it across the screen, marking out a rectangle as you do so. Voil`a you have
a window (Figure 3). You can have as many as you want. Left-click in any window to bring it to the front.
Figure 1. Rio opening screen (in a terminal window) yes, its all blank gray.
-5-
-6This is like having | more built into the output of everything that sends characters to the screen. If you really dont like this behavior, just middle-click in the
existing window and choose Scroll, or alter your profile to launch rio -s instead of
plain rio.
2.3. Mouse usage in rio
Left-click to bring any window to the front.
Left-drag the edges or corners of any window to resize it.
If the window holds more text than you can see, then there is a scroll bar at the
left of it (Fig. 3). With the mouse on the scroll bar, you can left-click to move up,
right-click to move down, or middle-drag to move up and down. You can also
scroll with the and keys.
To make a window go away, right-click on the background, choose Delete, and
right-click on the window.
The left button is also used to select text. Click once, and you move the cursor
(which is a zero-length selection) to the place where you clicked. Double-click,
and you select the whole word. To select more than a word, click and drag. Or,
to select a string of words that are in quotes or parentheses, double-click just
inside the quote or parenthesis.
As in other GUIs, when you type, your typing will replace what is selected.
The middle button brings up the following menu:
cut
paste
Paste the contents of the snarf buffer at the current insertion point.
snarf
plumb
send
Paste the contents of the snarf buffer into the window after the output
point (not the current selection, but the end of the text in the window)
and simulate pressing Enter. This is a quick way to send a command
to the system.
scroll
Inspired by Niklaus Wirths Oberon system, acme is a minimalist full-screen editing and development system. In operation, it looks something like Figure 4.
Kill
Putall
-9-
Dump
Exit
Leave Acme.
Column menu
New
Cut
Delete the selected text from the screen and place it in the snarf
buffer.
Paste
Copy the snarf buffer into the text at the insertion point.
Snarf
Copy the selected text into the snarf buffer (from anywhere in the
column).
Sort
Zerox
Create a copy of the current panel (thus giving you two windows
into the same file).
Delcol
Panel menu
filename The name of the file being edited. You can type over it to specify
that the next Put will use a different filename.
Del
Delete the whole panel (not the selection!). If the contents are
"dirty" (need saving), you will get a warning, but a second Del
will succeed.
Snarf
Copy the selected text into the snarf buffer (from within this panel
only).
- 10 Undo
Put
Save the file to disk. (Not shown if the file doesnt need saving.)
Look
- 11 You can execute "Look" without an argument, in which case it will use the
selected text in the editing panel as its argument.
Either way, "Look" means "find the next occurrence of this text and select it."
You can type other commands after the bar. In particular, if you type
Edit s/abc/def/g
you change all occurrences of abc to def throughout the selection (not throughout the file). To do a search-and-replace throughout the file, type
Edit ,s/abc/def/g
where the comma denotes an unlimited range of lines.
Any command from the editor sam can be typed in acme this way.
3.6. Mouse usage
A quicker way to find the next occurrence of a word is to right-click the word
itself. To do this to a phrase that contains a space, you can either right-sweep the
phrase (drag across it while holding down the right button), or select it (by leftdragging) and then right-click on it.
The use of the left and middle buttons has already been described. (The left button selects text in all of the ways that work in rio.) Much more information about
acme, including the use of mouse-button "chords" (combinations), is described in
man acme.
4.
To access a Plan 9 system from a Linux, Windows, or MacOS system, you will
run
a
terminal
emulator
called
drawterm,
available
from
/sys/src/cmd/unix/drawterm or http://swtch.com. Normally, you will
write a script to start drawterm with the right CPU server and authentication
server as arguments, such as:
drawterm -c minooka.coraid.com -a tyty.coraid.com
Under Windows, add start /w at the beginning of the command to give
drawterm its own window.
When drawterm launches, it will complain that it "cannot chdir to" a directory on
your PC. That is not a problem.
Drawterm acts like the console of a Plan 9 system; you can create windows in the
usual way. In addition, drawterm mounts the root directory of the (first) hard
disk of your PC into /mnt/term in addition to whatever is already mounted there.
That enables you to copy files back and forth between Plan 9 and the PC
- 12 transparently.
The Windows version of drawterm has a known problem you can read and
write the PCs hard disk but not list its directories. Thus
lc /mnt/term/Windows
will not show anything, but you can still read and write particular files on the PC
by name. To sort this out, try a Plan 9 command such as
date >/mnt/term/myfile.txt
and see where myfile.txt ends up.
5.
Reading documentation
The man command works as in UNIX, but you do not have to specify paging or
pipe to more because the Plan 9 screen does not scroll.
To view man pages elegantly converted to PostScript, use the -P option, as in:
man -P lc
To view PostScript, PDF, JPEG, and numerous other graphical formats, use page,
as in:
page myfile.pdf
Page has a middle-button menu for advancing to the next page, etc.
6.
The classic UNIX troff program is available in Plan 9 and understands UTF-8encoded Unicode (normal Plan 9 text). Here I give only a quick conceptual orientation to troff, with references to fuller documentation.
6.1. Running troff
Troff -ms input files normally have names ending in .ms, indicating use of the
troff -ms macros. A typical command to run troff (at Coraid) is:
troff -ms -mpictures myfile.ms | dpost -f | ps2pdf > myfile.pdf
That is: load the ms and mpictures macro packages and process myfile.ms, then
pipe it to dpost (which converts it to PostScript), then pipe it to the PDF converter.
\- dash or minus sign (longer than hyphen). See man kbd for how to type an
em dash or up-arrow directly.
\
required space (typed as \ followed by a space); joins words to be treated as
a single word.
\(ua up-arrow (many other special character codes resemble this one).
\fR switch immediately to roman type.
\fI switch immediately to italic type.
\fB switch immediately to bold type.
\f(BI switch immediately to bold italic type.
The normal way to switch to italics, boldface, etc., is to use ms macros such as .I,
- 14 .B, .R (italics, bold, roman). These are used in three ways. First, you can start a
block of text with .I and end it with .R, like this:
.I
This text will be
set in italics.
.R
Now we are back to roman.
Second, you can write the macro with one word right after it (or multiple words
joined with backslash-space):
We will have just one
.I word
in italics.
Third, you can add a second argument, which is something (typically a punctuation mark) that should immediately follow the italicized word but be set in
roman type, with no intervening space:
Did you say
.I bonjour ?
I thought so.
To learn more about troff, see the manual pages for troff, ms, and man, and
/sys/doc/troff.ps, then perhaps use the documentation and tutorials that
are abundant on the World Wide Web.
7.
Programming in C
- 15 -
minooka# 8c myfirst.c
minooka# 8l -o myfirst myfirst.8
minooka# myfirst
Greetings, earthlings!
Note that the first step creates myfirst.8; the second step would create 8.out if it
were not told to create myfirst instead; and in the third step, you do not have to
write ./myfirst because in Plan 9, your current directory is already in your
search path.
7.2. About u.h
In the sample program, the line
#include <u.h>
defines architecture-dependent types and macros such as uintptr and va_start,
plus abbreviations such as vlong used by the standard system header files, and
should thus always be included before any other header files. To learn more
about this and other headers, see man 2 intro.
7.3. For more information
To learn more about the C compiler, and especially its Unicode-compatible i/o
system, see /sys/doc/comp.ps and /sys/doc/compiler.ps on your Plan 9 system.
7.4. The low road: pcc
If all you want to do is compile a UNIX program to run under Plan 9, and you
arent interested in maximum performance, you can use the POSIX-compatible C
compiler, pcc. In this situation you will use UNIX headers such as stdio.h and
functions such as printf, leave out any mention of u.h, and compile and run your
program this way:
minooka# pcc -o mysecond mysecond.c
minooka# mysecond
Hello, world!
This uses APE, the POSIX-compliant subsystem of Plan 9.
- end -