Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ For detailed information about the config file format, see [Config File Format](
### User command

The User command feature allows you to execute custom external commands.
You can display the output of commands like `git diff` in a dedicated view, or execute commands like branch deletion in the background.
You can display the output of commands like `git diff` in a dedicated view, execute commands like branch deletion in the background, or run interactive commands like `vim` by suspending the application.

For details on how to set commands, see [User Command](https://lusingander.github.io/serie/features/user-command.html).

Expand Down
5 changes: 3 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
"description": "The type of user command.",
"enum": [
"inline",
"silent"
"silent",
"suspend"
],
"default": "inline"
},
Expand All @@ -116,7 +117,7 @@
},
"refresh": {
"type": "boolean",
"description": "Whether to reload the repository and refresh the display after executing the command. Only available for 'silent' commands.",
"description": "Whether to reload the repository and refresh the display after executing the command. Available for 'silent' and 'suspend' commands.",
"default": false
}
},
Expand Down
4 changes: 3 additions & 1 deletion docs/src/configurations/config-file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ For details about user command, see the separate [User command](../features/user
- possible values:
- `inline`: Display the output of the command in the user command view.
- `silent`: Execute the command in the background without opening a view.
- `suspend`: Execute the command by suspending the application. This is useful for interactive commands.
- `commands`: `array of strings` - The command and its arguments.
- `refresh`: `boolean` - Whether to reload the repository and refresh the display after executing the command. Only available for `silent` commands.
- `refresh`: `boolean` - Whether to reload the repository and refresh the display after executing the command. Available for `silent` and `suspend` commands.
- default: `false`
- examples:
- `commands_1 = { name = "git diff", commands = ["git", "--no-pager", "diff", "--color=always", "{{first_parent_hash}}", "{{target_hash}}"]}`
- `commands_2 = { name = "delete branch", type = "silent", commands = ["git", "branch", "-D", "{{branches}}"], refresh = true }`
- `commands_3 = { name = "amend commit", type = "suspend", commands = ["git", "commit", "--amend"], refresh = true }`

### `core.user_command.tab_width`

Expand Down
12 changes: 9 additions & 3 deletions docs/src/features/user-command.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
# User Command

The User command feature allows you to execute custom external commands.
There are two types of user commands: `inline` and `silent`.
There are three types of user commands: `inline`, `silent` and `suspend`.

- `inline` (default)
- Displays the output (stdout) of the command in a dedicated view within the TUI.
- This allows you to do things like view commit diffs using your favorite tools.
- `silent`
- Executes the command in the background without opening a view.
- This is useful for operations that don't require checking output, such as deleting branches or adding tags.
- `suspend`
- Executes the command by suspending the application.
- This is useful for interactive commands that require terminal control, such as `git commit --amend` (which opens an editor) or `git diff` with a pager.

To define a user command, you need to configure the following two settings:
- Keybinding definition. Specify the key to execute each user command.
- Config: `keybind.user_command_{n}`
- Command definition. Specify the actual command you want to execute.
- Config: `core.user_command.commands_{n}`

**Configuration example:**
Example configuration in `config.toml`:

```toml
[keybind]
user_command_1 = ["d"]
user_command_2 = ["shift-d"]
user_command_3 = ["b"]
user_command_4 = ["a"]

[core.user_command]
# Inline command (default)
Expand All @@ -31,11 +35,13 @@ commands_1 = { "name" = "git diff", commands = ["git", "--no-pager", "diff", "--
commands_2 = { "name" = "xxx", commands = ["xxx", "{{first_parent_hash}}", "{{target_hash}}", "--width", "{{area_width}}", "--height", "{{area_height}}"] }
# Silent command with refresh
commands_3 = { "name" = "delete branch", type = "silent", commands = ["git", "branch", "-D", "{{branches}}"], refresh = true }
# Suspend command with refresh
commands_4 = { "name" = "amend commit", type = "suspend", commands = ["git", "commit", "--amend"], refresh = true }
```

## Refresh

For `silent` commands, you can set `refresh = true` to automatically reload the repository and refresh the display (e.g., commit list) after the command is executed.
For `silent` and `suspend` commands, you can set `refresh = true` to automatically reload the repository and refresh the display (e.g., commit list) after the command is executed.
This is useful when the command modifies the repository state.

Note that `refresh = true` cannot be used with `inline` commands.
Expand Down
Loading