Northern Commander

The shell and its integration

The terminal runs your own shell, as a login shell, with your own start-up files. Small scripts the application adds tell it where the shell is and where each command starts and ends — which most of the terminal’s features stand on.

KeyAction
⌘GMove the shell to a folder…

Which shell

Built-in terminal shell chooses it:

Set to Runs
automatic, as shipped Your login shell
A name, such as fish That shell, looked for on the path and in /opt/homebrew/bin, /usr/local/bin, /bin and /usr/bin
A full path That program

A shell that cannot be found is replaced by your login shell. A change counts from the next shell started — a new tab.

  • Always a login shell, so your path and everything else a login sets up are there, as in a new window of any terminal application.
  • In the active pane’s folder, or your home folder where that is not a folder on this Mac.
  • Told where it is running: TERM is xterm-256color, COLORTERM is truecolor and TERM_PROGRAM is NorthernCommander. NORTHERN_COMMANDER_SHELL_LEVEL counts how many of these terminals it is inside.
  • Without another terminal’s traces: variables another terminal application left behind — its name, its session, the old window size — are taken out, so no program thinks it is running there.
  • With a language: where none is set, LANG is en_US.UTF-8, so characters beyond ASCII come out right.

Shell integration

For zsh, bash and fish, the shell is started with a few scripts of the application’s that report three things: the folder it is in, at every prompt; where each prompt, typed command and output begin and end, with the command’s exit code; and each command’s text as it starts.

  • They are kept in the application’s own folder, readable by you alone, and never written into your files. Your own start-up files are read as usual.
  • Any other shell runs without them, as does every shell while Shell reports where it is is off.

What needs it

  • Moving the shell to the pane’s folder as the command line takes the keyboard, and a shell beside a pane following the pane — and the pane following the shell.
  • Knowing when a command from the command line has ended: the notice, and going back to the panes.
  • Esc clearing the command line, and Esc twice leaving the terminal.
  • Stepping through commands, the files in their output, and the last command’s output in the viewer.
  • The command history list.
  • Clicking in the command you are typing to move the cursor there.
  • Running a typed line in iTerm2 or Terminal.
  • A tab’s • and ?, and titling it by its command.

Without it, each of these is missing rather than guessed at: Esc on the command line always gives the keyboard back, a command run from the line brings up the terminal once the delay has passed and leaves it up, and closing a tab or quitting asks first whenever a shell is open, since none can say it is idle.

zsh, bash and fish

zsh
Marks where typing begins as its line editor starts, so a prompt theme that builds its prompt afresh each time does not disturb it.
bash
Keeps that mark in PS1. A prompt framework that builds PS1 afresh at every prompt drops it, and then the application cannot tell what is typed: Esc on the command line gives the keyboard back rather than clearing, whatever is put on the line — from the history, the user menu — clears it first, and there is no Run in row. The integration also needs a DEBUG trap of its own; if you have set one, or a framework takes it over, yours is kept: commands go unmarked and unreported, the shell is not moved to follow a pane, and a command from the command line brings up the terminal only if it takes the whole screen.
fish
Marks where typing begins after its prompt. Like fish’s own history, it leaves out a command starting with a space. fish cuts a prompt wider than the terminal down to its width, and typing then begins on the row below: under the panes the command line shows that row without the prompt, unless Command line shows is whole prompt.

Shells inside the shell

A shell you start inside the terminal — ssh to another machine, or bash typed at zsh — is not given the scripts, so none of this reaches inside it. To the terminal it is one command that has not finished:

  • The tab shows •, or ? while it waits for you.
  • Nothing you run in it goes into the command history, and ⌘↑ steps over the whole of it as one command.
  • The pane does not follow it, and ⌘G says the shell is busy.
  • ⌘L opens a new tab of its own, with a shell on this Mac, rather than typing into it.

A folder that a shell on another machine reports is ignored: a pane has nothing to follow there.

Moving the shell

⌘G — in the full terminal, or in a terminal beside a pane — asks for a folder and moves the shell there. It is the same box as going to a folder over the panes, and offers the active pane’s folder first, or the folder of the pane beside the terminal.

  • Nothing is typed at the shell: its integration moves it. Nothing is added to its history, and what you had typed stays on the line — bash puts the line aside and back, with the cursor at its end.
  • Only a shell waiting at its prompt is moved. Otherwise it says why: The shell is busy, so it was not moved, or This shell has no integration, so it cannot be moved.
  • The command line moves the shell the same way as it takes the keyboard, and so does a shell following the pane beside it.

Over the panes the same key is ⌘G, for the pane.

What a program in the terminal cannot do

A shell runs whatever you type in it. What the terminal guards against is anything running that you did not type.

  • The application runs nothing you did not ask for. It moves the shell through the integration, never by typing, and what it puts on the line — a name, a command from the history — waits there for your Enter. A command from the user menu runs because you chose it.
  • A program is never told what is on your clipboard, and, with Programs may use the clipboard off as shipped, cannot put anything on it.
  • A program’s requests are answered only about the terminal itself — the cursor’s position, its modes, its colors. Anything that would send text back into the shell’s input as if typed, such as the window’s title, is dropped.
  • Nothing a program prints can add to your history. Each command is reported with a secret the shell reads once as it starts and then removes.
  • A folder on another machine is never followed, and never taken for one of this Mac’s.