Customization
Custom commands
15 min read
A custom command is a command line that you (or your team) register once and then run from inside Versora, without opening the terminal: from the palette, from the menus of the tab, branch, commit, file or commit selection, or with a keyboard shortcut.
It can have parameters: before running, Versora shows a form that asks, for example, for a branch from the list, a name with the right format or a confirmation, and shows the exact command that will run. Everything runs without a shell, with live output, a button to cancel and Ctrl+Z to undo what the command changed in branches, tags and HEAD.
There are two kinds, with the same format and the same engine:
| Kind | Where it lives | Who sees it | Label in the palette |
|---|---|---|---|
| My commands (personal) | Preferences › Custom commands, in your Versora. | Only you, in every repository. | "My command: ‹name›" |
| Team commands | The commands: list in the .versora.yml file at the root of the repository. | Everyone who opens the repository. | "Team command: ‹name›" |
- Preferences › Custom commands › My commands: New command and From a template… buttons.
- Palette (Ctrl+P): "New custom command…" (opens the editor directly) and "Manage custom commands" (opens the section).
- Open the palette and choose "New custom command…", or click New command in Preferences.
- In Name, write how it will appear in the palette and the menus. You can use variables, such
as
Log of {branch}: in a branch's menu, the item appears as "Log of feature/login…". - In Description (optional), write a sentence. It appears below the name in the palette. Without a description, the palette shows the command itself.
- In Command, write the program and the arguments, for example
git log --oneline -20 {branch}. The Insert: buttons put a variable where the cursor is. - In Shows up in, check the places: palette, repository menu, branch menu, commit menu, file menu and selection menu.
- If the command needs values chosen at run time, click Add parameter (see Parameters).
- In Undo (Ctrl+Z), choose how Ctrl+Z should handle what the command changes.
- Follow the check below: "Valid command." and, with a repository open, "With the initial values, in ‹repository›, it will run:" followed by the exact line.
- If you want to try it before saving, click Test… (runs the command as it is now, without saving, in the tab's repository).
- Click Save. The notice confirms: "Command "‹name›" saved.".
| Field | What it does | Default |
|---|---|---|
| Name | How it appears in the palette and the menus (up to 80 characters). Accepts app variables. | (empty) |
| Description (optional) | Supporting text in the palette. | (empty) |
| Command | Program and arguments, without a shell. Quotes group an argument with spaces. Variables in braces, such as {branch}. | (empty) |
| Shows up in | palette, repository menu, branch menu, commit menu, file menu, selection menu. | palette |
| Parameters | What the form asks for before running (up to 12). | none |
| Undo (Ctrl+Z) | "undoes refs and files (hard)", "undoes refs and keeps the changes (soft)", "undoes refs and keeps the changes unstaged (mixed)" or "not undoable". | hard |
| Keep a copy of the files first | Ctrl+Z also restores the files the command changes. Disabled with "not undoable". | Unchecked |
Footer buttons: Show as YAML (and Hide YAML), Cancel, Test… (only with a repository open and a command that appears in the palette or in the repository menu) and Save (only with a valid command).
If you leave the editor with unsaved changes (with Cancel or Esc), Versora asks "Discard changes?" ("The changes to this command haven't been saved.").
From a template… opens a list of ready-made commands to adapt. Each one shows a way to use parameters:
| Template | Command | Shows up in |
|---|---|---|
| Create a prefixed branch (list, formatted text, branch) | git switch -c {prefix}/{topic} {base}, with Kind (feature, bugfix, hotfix), Name (only lowercase letters, digits, dot, hyphen and _) and "Starting from" (default: the current branch) | palette, branch menu |
| File history (file menu, list) | git log --oneline -{n} --follow -- {file}, with "How many commits" (10, 50 or 200) | file menu |
| Selection summary (selection menu) | git diff --stat {oldest_sha}~1 {newest_sha} | selection menu |
| Run an npm script (list) | npm run {script}, with Script (test, lint, build) | palette, repository menu |
| Delete the branch on the remote (remote, dangerous confirmation) | git push {remote_name} --delete {branch}, with Remote and a red confirmation | branch menu |
They work in the Name, in the Command, in the parameters' initial value and in the
confirmation questions. Write them in braces. For a literal brace, use {{ and }}.
| Variable | Value | Where it has a value |
|---|---|---|
{repo} | The repository folder. | Everywhere |
{branch} | The current branch. In a branch's menu, the menu's branch. | Everywhere |
{sha} | The full SHA of HEAD. In a branch's menu, its tip; in a commit's menu, the commit. | Everywhere |
{short_sha} | The first 8 characters of {sha}. | Everywhere |
{remote} | The branch's remote (the upstream's). With no upstream, origin or the first remote. | Everywhere |
{file} | The file path, relative to the root, with /. | Only in the file menu |
{shas} | One argument per selected commit, from oldest to newest. It must be alone in an argument. | Only in the commit and selection menus |
{oldest_sha} and {newest_sha} | The oldest and the newest commit in the selection. | Only in the commit and selection menus |
A command that uses a variable in a place that doesn't have it is rejected on save, with the
reason: "{file} only has a value in: …; keep only those places in where".
The values also reach the program as environment variables: VERSORA_ followed by the name in
uppercase (VERSORA_REPO, VERSORA_BRANCH, VERSORA_SHA…). Each parameter arrives as
VERSORA_PARAM_ followed by its key in uppercase.
Each parameter becomes a field in the form that appears before running. The app checks each value before using it.
Type (type) | Name on screen | What the person does | What goes into the command |
|---|---|---|---|
text | Text | Types. Accepts an initial value, example text, a format (regular expression) and a hint. Can't start with "-". | The text |
branch | Branch | Picks a local branch, a remote one or either (Branches offered: Local, Remote, Local and remote). The app checks that it exists. | The branch name |
tag | Tag | Picks a tag from the repository. | The tag name |
remote | Remote | Picks a remote from the repository. | The remote name |
commit | Commit | Picks a commit from the list or types a revision (HEAD~2, a tag…). | The full SHA |
file | File | Picks a file from the repository (tracked ones and new ones .gitignore doesn't ignore). | The relative path, with / |
choice | Option from a list | Picks one of the options defined in the command. | The option's value |
flag | Checkbox | Checks or unchecks. | The checked value (for example --force) or the unchecked one; if blank, the argument is dropped |
confirm | Confirmation | Answers a question before running. With "dangerous action", the button turns red and focus starts on Back. | Nothing |
| Field | Applies to | What it does |
|---|---|---|
| Type | all | One of the types above. |
| Variable | all except confirmation | The name used in the command, in braces. Lowercase letters, digits and _, starting with a letter (up to 32). It can't repeat or be the name of an app variable. |
| Label in the form | all | The text next to the field. In the confirmation, it's the "Confirmation title". |
| Initial value | text, branch, tag, remote, commit, file, choice | What comes already filled in. It can use app variables, such as {branch}. In a list, "(none: the person picks)". |
| Example text in the field | text | The gray text inside the empty field. |
| Format (regular expression) | text | For example ^[a-z0-9-]+$. The hint becomes the message when the value doesn't match. |
| Hint below the field | text and others | A short explanation below the field. |
| Required | text and others | Without a value, the form doesn't run ("fill in this field"). |
| Branches offered | branch | Local, Remote or Local and remote. |
| Options | choice | One per line: value or value = label (up to 50). |
| Checked value / Unchecked value / Checked by default | flag | What goes in with the box checked (e.g. --force), with it unchecked (blank: the argument is dropped) and the initial state. |
| Question / Dangerous action | confirm | The question text (it can use variables and other parameters, such as Delete {branch}?) and whether the button turns red, without confirming with Enter. |
An argument that's only a parameter and was left empty (unchecked box, optional text left blank) is dropped from the line, instead of becoming an empty argument.
- Palette: "My command: ‹name›" and "Team command: ‹name›" (the ones that have "palette" in Shows up in).
- Context menus: My commands and Team commands submenus in the menus of the tab (repository), the branch, the commit, the file and the graph's commit selection.
- Preferences › Custom commands: Run… button next to each command that appears in the palette or in the repository menu.
- A keyboard shortcut, if you gave it one (see Keyboard shortcuts).
- Choose the command. In a branch's or commit's menu, the variables come with that branch's or commit's value.
- If it has parameters, fill in the form. The Will run box shows the exact line and updates with each change ("Checking…"). While something is missing: "Fill in the fields above to see the command.".
- Click Run (or Enter in a field). If there's a confirmation, it appears: Back or Confirm and run.
- The output appears live in "Command output". The end says "Finished successfully (code 0, …)." or "Finished with an error (code N, …).".
- To stop midway, click Cancel the command. The result is "Canceled.".
- At the end, Run again… goes back to the form with the values you used (for a command without parameters that's already trusted, it runs again directly) and Close closes the window.
Commands you didn't create on this computer show the exact command before running and ask for your confirmation:
- Team command: "This command comes from this repository's .versora.yml. Check it first: it runs with your permissions, on your computer." The window shows the command "As written in the file" and the folder ("In folder").
- Imported personal command (it came from "Import settings" or was created on another computer): "This personal command came from imported settings or was created on another computer. Check it before running." The window shows the command "As stored".
Below comes the reminder "Only trust commands you understand. If the command changes, Versora asks again." and the buttons:
- Run just this once: runs now and asks again next time.
- Trust and run: runs and doesn't ask again as long as the command stays the same.
- Cancel: doesn't run.
With the trust request on screen, Enter in a field doesn't run the command: you choose the button. For a command without parameters, focus starts on Cancel.
Trust applies to that repository and to that content: name, program, arguments, places and
parameters. If the command changes in .versora.yml (in a pull, for example), Versora asks again.
In the Preferences list, a personal command that will still ask for confirmation has the "asks for
confirmation next time" badge.
To stop trusting a team command, open Preferences › Policy and team, Team commands group, and click Stop trusting. The notice confirms: ""‹name›" will ask for confirmation again.".
Versora doesn't use a shell: it separates the program from the arguments, replaces the variables
with their values and runs the program directly, found through the PATH, in the repository's
root folder, with no console window and no keyboard input. For example, the "Create a prefixed
branch" template with Kind feature, Name login and "Starting from" main runs:
git switch -c feature/login main
That's why |, &&, > and redirections don't work in the command line: they'd be passed to the
program as text. For a pipeline, call a script from the repository, for example
powershell -File scripts/publicar.ps1 or npm run publicar, and read the values in the
VERSORA_* environment variables.
Only one custom command runs at a time, and the tab is busy while it runs. At the end, the graph is updated with the branches and tags the command created or moved.
If the command changed branches, tags or HEAD, Ctrl+Z goes back to the state
from before (the operation appears as "Command "‹name›"" in the timeline).
What comes back depends on the mode chosen in Undo (Ctrl+Z) (in .versora.yml, undo:):
| Mode | undo: | What Ctrl+Z does |
|---|---|---|
| undoes refs and files (hard) | hard | Restores branches, tags and HEAD and the files to the state from before. It's the default. |
| undoes refs and keeps the changes (soft) | soft | Restores the refs and leaves the changes staged. |
| undoes refs and keeps the changes unstaged (mixed) | mixed | Restores the refs and leaves the changes unstaged. |
| not undoable | off | Nothing: use it for commands that only read (log, diff, tests). |
With "Keep a copy of the files first" (snapshot: true), Versora keeps the files before running
and Ctrl+Z restores them too. What the command did outside the repository
(sending something to the server, deleting a branch on the remote, publishing a package) doesn't
come back.
Caution
A push, a git push --delete or any call to a server has already happened by the time the output
ends. Ctrl+Z only undoes what changed in your local repository.
- "A custom command is already running.": wait for the other one to finish or cancel it.
- "the tab is busy with another operation; try again when it finishes": a fetch, pull or another operation is in progress in the tab.
- "This command's repository isn't open in a tab.": open the repository first.
- "Can't run "‹name›" right now: …": a value is missing, for example "the command uses
{branch}, but there's no value right now (for example, detached HEAD or no remote)". - "program not found: …": the program in the first word isn't on the
PATH. - "can't start with "-" (the program would read it as an option)": a typed text starts with a hyphen.
- "doesn't match the expected format (…)": the text doesn't match the parameter's format.
- "branch … doesn't exist", "tag … doesn't exist", "remote … doesn't exist", "not a commit in this repository: …", "file … doesn't exist in the repository": the value doesn't exist.
- "has characters ‹program› could run as code; use only letters, digits and . _ / @ + = , : ~ # -
(the script receives the full value in the VERSORA_PARAM_… environment variable)": the program
is a
.cmd,.bat, PowerShell or another shell, and the typed value has characters it would interpret. Use the environment variable in the script. - "the value of
{branch}(…) has characters a program could interpret; the command didn't run.": a branch or remote name coming from someone else has dangerous characters. - "the command changed in .versora.yml since it was shown; check it again" and "the command is no longer in .versora.yml": the file changed between the window opening and you clicking run.
- "Team commands were turned off by your company's policy.": IT turned off the
.versora.ymlcommands on this machine.
Each row in the My commands list shows the name, the command, the places ("Shows up in: …"), the number of parameters and the undo mode, with the buttons:
- Run… (for the ones that appear in the palette or in the repository menu);
- Edit and Duplicate (the copy is called "‹name› (copy)");
- ↑ and ↓, which change the order in the list and in the menus;
- Delete, with the confirmation "Delete "‹name›"?" ("The command leaves the palette and the menus. Any shortcut it had stops working.").
You can have up to 200 personal commands. A command with an error appears in the list with the reason and stays out of the palette and the menus until it's fixed.
- Open the command in the editor and click Show as YAML.
- Copy the text shown ("To share this command with the team, paste the item into the repository's .versora.yml (inside commands:, if the file already has that list).").
- Paste it into the
.versora.ymlat the repository root, commit and push. - Whoever opens the repository will see the command in the Team commands submenu and, on first use, the trust confirmation.
commands: # nothing runs without each person's confirmation
- name: Run the tests
description: Unit tests
run: npm test # no shell: program + arguments
where: [palette, repo]
undo: off
- name: Log of {branch}
run: git log --oneline -20 {branch}
where: [branch]
undo: off
- name: Show commit
run: [git, show, --stat, '{sha}']
where: [commit]
undo: off
- name: New feature from {branch}
id: new-feature # stable: it's the shortcut's id (custom:team:new-feature)
run: git switch -c feature/{name} {base}
where: [palette, branch]
params:
- key: name
type: text
label: Feature name
pattern: '^[a-z0-9-]+$'
hint: Only lowercase letters, digits and hyphens
- key: base
type: branch
label: Starting from
default: '{branch}'
- type: confirm
message: Create feature/{name} from {base}?
| Key | What it is | Default |
|---|---|---|
name | Name in the palette and the menus (required, up to 80 characters). | — |
id | Stable id, used by the shortcut (custom:team:<id>). | Generated from the name |
description | Supporting text in the palette. | — |
run | Program and arguments: a text (quotes group) or a list. The first word can't be a variable. | — |
where | List of places: palette, repo, branch, commit, file, selection. | [palette] |
params | List of parameters, with key, type, label, default, placeholder, pattern, hint, required, scope (local, remote, all), options (value and label), value and off_value (flag), message and danger (confirm). | — |
undo | hard, soft, mixed or off. | hard |
snapshot | true keeps a copy of the files first. | false |
The same types and rules as the editor apply here. An error in the file appears with the reason, for example "where accepts: palette, repo, branch, commit, file, selection", "name is missing", "the program (first word of run) can't come from a variable" or "unknown type "…"; accepted types: text, branch, tag, remote, commit, file, choice, flag, confirm".
The other .versora.yml rules (commit message, protected branches, AI trailer) are in
.versora.yml.
Each command has a stable id in the palette: custom:user:… for yours and custom:team:… for the
team's. In Preferences › Keyboard shortcuts, look for the command by name in the Palette
commands group and record the key. The shortcut keeps working when you rename it. If the command
disappears (for example, a team command from another repository), the shortcut stays saved and the
row appears as "not available now". See Keyboard shortcuts.
- Your commands are included in "Export settings" on Home. On a new computer, each imported command shows the exact command and asks for confirmation on first use. The trust itself is never exported.
- The trust in team commands is kept inside the repository's
.gitfolder (versora/policy-consents.json). A fetch or pull doesn't write there. - IT can turn off team commands on every machine with
team_commands: denyand hide or lock the page with the idcustom-commandsinpreferences_hiddenorpreferences_locked. See Policy keys.
For IT
Team commands come from the repository, that is, from anyone with push permission. That's why nothing runs without each person's confirmation, the program can't come from a variable, the values are checked on every run and the backend rereads the file before running to make sure the command is the same one the person saw.