The user menu
The user menu holds commands you write yourself — a line or two of shell each, on a key of its own. Choosing one fills in the file under the cursor, the marked files or either pane’s folder, and runs it.
| Key | Action |
|---|---|
| ⌥F9 | User menu |
Choosing a command
⌥F9 opens the menu over the active pane.
- A command’s letter chooses it, held with ⌥ — which you are already holding from opening the menu. A command on a digit or a symbol is chosen without it.
- Typing narrows the list to the commands whose names hold what you typed; Enter chooses.
- Beside each name is what it would run now, filled in.
- A command whose placeholders have nothing to stand for is grayed and cannot be chosen —
{name}with the cursor on.., or{there}while the terminal stands in the other pane’s place. So the menu has the same rows wherever you open it. - A name ending in … asks first, or goes onto the command line — below.
- Two commands on one letter: the letter moves between them and chooses neither; Enter chooses.
- ⌥F9 again, with the menu open, opens the form that changes it. Edit the user menu…, at the bottom, has no letter, so every letter is yours; it shows that key where a letter would be.
Writing a command
Edit the user menu… — at the bottom of the menu, in the Commands menu, or ⌥F9 twice — opens the form.
- Add…
- A new command, at the end of the list.
- Edit…
- The command chosen — Enter does the same.
- Remove
- The command chosen.
- Move up · Move down
- Its place in the menu.
- Open the file
- Closes the form and opens
user-menu.jsonin the editor.
Every change is written to user-menu.json as you make it, and the menu opened next shows it.
- Name
- What the menu shows.
- Menu letter
- One character, or none. More than one is kept as none. A command with no letter is chosen by typing its name.
- Command
- One or more lines of shell, with placeholders.
- When selected
- What choosing it does — below.
- Always in a terminal tab of its own
- Runs it in a new terminal tab every time.
- Keyboard shortcut
- A key of its own that runs the command without opening the menu, the same as choosing it there. Set… takes the next key you press, and Clear takes it off. If the command needs something the panes cannot give it, such as a file under the cursor, the key does nothing.
OK is grayed until the command has a name and something to run.
Placeholders
| Write | For |
|---|---|
{name} |
The item under the cursor, by name |
{path} |
The same item, in full |
{names} |
The marked items by name — or the item under the cursor, when none are marked |
{paths} |
The same items, in full |
{here} |
The active pane’s folder |
{there} |
The other pane’s folder |
- Each is quoted for your shell where it needs to be, one word per item:
wc -l {name}on to do.md runswc -l 'to do.md'. Put no quotes of your own around one. - A name starting with
-goes in as./-name, so no program takes it for an option. - An item that is not in the pane’s own folder — in search results — goes in
as its full path, even for
{name}. - Only these six words, and only in braces, are replaced. Anything else in braces, such as
{a,b}, is left for your shell.
What choosing one does
| When selected | Choosing it |
|---|---|
| Run immediately | Runs it |
| Ask for confirmation | Shows it filled in, to Run or Cancel. It cannot be changed there |
| Edit on the command line | Puts it on the command line in place of what is there, and runs nothing until you press Enter |
The last two show … after their name in the menu.
Where it runs
A command runs as one typed on the command line does: in the active pane’s folder, in the built-in terminal, which comes up only if there is something to see, with a notice of how it went, and into the command history.
- What you had typed on the command line is never lost. A command that runs while something is typed there, or while the shell is busy, runs in a terminal tab of its own — as does one set to Always in a terminal tab of its own.
- A command of several lines is pasted as one, which needs a shell that takes a paste whole, as zsh does. Where the shell does not, the application says so and runs nothing.
- Edit on the command line while the shell is running something puts nothing on the line, and says so.
The file
The commands are in ~/.northern-commander/user-menu.json, and the file is meant to be edited by hand
as much as on the form. It is read again every time the menu or the form opens, so a change counts at
once.
{
"version": 1,
"commands": [
{ "key": "g", "label": "Git status", "command": ["git status"] },
{ "key": "z", "label": "Zip the marked items", "command": ["zip -r archive.zip {names}"],
"whenSelected": "edit on the command line" },
{ "key": "b", "label": "Build and test", "command": ["cd {here}", "make test"], "newTab": true }
]
}
- version
- The shape the file is written in. The application writes it.
- commands
- The commands, in the order the menu shows them.
- key
- One character, the letter in the menu. Left out, or longer, the command has none.
- label
- Its name. Required.
- command
- Its lines, a string each. Required. A single string is read as one line.
- id
- What its key in
key-bindings.jsongoes by. The application adds it; leave it as it is. - whenSelected
ask for confirmationoredit on the command line. Left out, it runs immediately. Anything else, misspelled or not, asks for confirmation — a mistake here never runs a command unasked.- newTab
trueto run it in a terminal tab of its own.
An entry with no label or no command is left out of the menu. While the file holds one — or holds
commands as anything but a list, or is not JSON at all — the form will not write over it: a change
made there is refused with the reason, and the file stays as you wrote it. For JSON that is broken,
the reason says the line, and the next start moves the file beside itself as
user-menu.unreadable-<date>-<time>.json and tells you where, so the menu can be written again.
Its schema is https://northerncommander.com/schemas/user-menu.schema.json; add it as $schema for
an editor to check the file as you type. A backup can hold the file.