A window can be set to shell mode using the Settings menu. Also, you may toggle a window between being a regular document and being a shell by clicking the shell rectangle in the status bar:
In shell mode shell commands can be executed just as in a Terminal shell. You may for instance type ls and hit Return. In a traditional Unix Terminal shell one typically uses shell history to recall and reuse previously executed commands. While this is handy, it has been designed to work on a lowest common denominator environment of simple terminals and as a result is a bit inflexible.
In contrast, the shell window document in Eddie saves and allows editing just like in any regular document window. This gives the user a convenient alternative to the traditional shell history — common shell commands or interesting shell command output can be kept in the shell document for next time while temporary one-time commands simply get deleted. Shell commands can be edited via normal selection, copy-paste and other common editing techniques. There is an actual bash shell running in each shell window. You can use make, cd, ls, grep, etc. You may set shell variables, aliases and other shell state. In addition Eddie defines some built-in shell commands. All that, while editing still works the way it does in other document windows.
To execute a shell command, you type the command in and either use the "Execute" menu item or just hit return:
You will get something like:
Unlike in Terminal, you may now go back to the resulting output and edit it to execute some other command:
Note that in the "grep -n macro " inserted in the above example — we are trying to look up "macro" in the file bootstrap.log. Hitting the return to execute the new line will produce:
Now that you have found what you are looking for, you may clean up all of the resulting output by hitting Undo one or two times. Alternately, you can just use standard edits to delete the output that is not needed and to preserve for later whatever you need.
In the above examples we were executing the entire line by placing the cursor anywhere on said line. If you select only a part of a line and hit return, only the selected part will get executed:
In our example the output of ls gets inserted right after the executed command:
Note that only the selected ls part of the command got executed, the grep part was ignored. Also note that unlike in a normal edit, when executing a selection in the shell window, the executed selection does not get deleted first.
Once more to get rid of temporary shell output and keep it from polluting your shell window, you may use Undo.
Return | executes a selection or an entire line as a shell script |
Ctrl-Return |
acts as Return in a normal window - it just inserts a new line. This is useful when you do not want to execute the line you just typed in |
Ctrl-C | sends a break signal to the shell, stopping makes, etc. |
Tab |
completes a path; repeated use will bring up a popup panel with suggested completions |
Ctrl-Tab | inserts a tab character |
As with most other keyboard shortcuts, all of the above can be remapped. You may for instance prefer the more MPW-like mapping of Enter to act as an Execute command and Return to just insert a newline. You may do this by customizing your UserStartup file with the SetKey commands.
Shell prompts appear in the status rectangle in the button bar. If the shell is executing, a prompt will be light blue and a busy gear icon will show up - in the following example the shell window is busy executing a sleep command:
You may interrupt the current process using the usual Control-C command.
As with a terminal shell, you can customize the prompt format by adding a corresponding entry to the ~/.profile file. You may for instance add the following line:
PS1="\$PWD"" :"
Note that the shell does not support terminal escape sequences. It is therefore not possible to run tools like vi and more. Hopefully the editor text editing capabilities will offset for this deficiency. Telnet, more and other shell tools requiring terminal escape sequences won't work either.
Eddie Shell windows support tab completion. You can type in one or two characters of a path and hit Tab, Eddie will fill in the remainder of a path, unless there are several completions that can match the characters you already typed in. You may combine typing a character or two and hitting Tab repeatedly, just like in the Bash shell. When there are multiple or no possible completions, Eddie beeps.
If you hit Tab again, Eddie will suggest possible completions in a temporary panel. The
panel will disappear once you click the mouse or type another key. Like Bash, Eddie will
complete shell variables and use them when expanding pathnames. Unlike Bash, Eddie will
leave the variable in it's original symbolic form, the completion mechanism evaluates it
though to suggest a completion.
Local directories are highlighted in bold in the completion panel. If you hit Tab for the third time, if the typed text matches one of the local directories, it will be used as a completion, even if there are other matching completions elsewhere on the system.
Note that you can configure Eddie to use the $PATH environment when completing in the Shell pane of preferences. If you disable the "Use $PATH when Tab-completing" checkbox, Eddie will use just absolute paths and paths relative to your current directory.
The bash shell set up by Eddie exports some useful, Eddie-specific environment variables that can be used in shell commands.
$TARGET |
This variable returns the pathname of the document opened in the Target window. A Target window is the one behind your current window (i.e. behind your Shell or Worksheet) |
$ACTIVE |
This variable returns the pathname of the active/current window (i.e. the Shell or Worksheet, if you are executing a command you typed) |
$_TS |
Represents the current selection in the Target window. It can be read from (i.e. you can "cat $_TS") |
$TS_ |
Represents the current selection in the Target window. It can be written to (i.e. you can "echo 'better text' > $TS_") |
$_AS |
Represents the current selection in the Active window. It can be read from (i.e. you can "cat $_AS") |
$AS_ |
Represents the current selection in the Active window. It can be written to (i.e. you can "echo 'better text' > $AS_") |
$EDDIE_HOME |
The Eddie application parent directory path |
$EDDIE |
The Eddie application executable path |
The distinction between Target and Active windows seems subtle. In fact each of the two has it's use. For direct use from a Worksheet or Shell, $TARGET windows are preferable over $ACTIVE, $_TS and $TS_ over $_AS and $AS_, respectively, as you typically want the commands you are executing from the Shell to operate on the document behind your Shell, rather than on the shell commands you are trying to execute.
Active windows, $_AS and $AS_ came into play when using shell commands from the Context Menu, where you want the shell command to execute directly on the text in the active window.
$_TS and $TS_ along with $_AS and $AS_ are backed by named pipes that seamlessly integrate the Eddie text engine selection to the shell environment, while Eddie is running. They work equally well in the Worksheet as they do in any other shell script run from Terminal, etc.While the Worksheet and other Shell windows provide the best environment for shell command execution, it can sometimes be useful to quickly execute a shell command in a plain document window. When used from an arbitrary document, the Execute command creates a temporary bash shell that for the duration of execution of the command. The shell's current directory is set to be the parent of the respective document.
This will indeed spew "hello world" into your source file, right next to the compile command.
The resulting shell output can be either used or dismissed using Undo. Handy shell commands
can be kept in the document, commented out and ready for execution, as in the example above.
Command-Option-Control-Return | executes a selection or an entire line as a shell script |
Ctrl-C | sends a break signal to the shell, stopping makes, etc. |