2020-10-05 02:33:12 -07:00
|
|
|
|
---
|
|
|
|
|
id: command
|
|
|
|
|
title: Command
|
|
|
|
|
sidebar_label: Command
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## What
|
|
|
|
|
|
2022-08-23 07:47:55 -07:00
|
|
|
|
:::caution powershell
|
|
|
|
|
While powerful, it tends to take a lot of time executing the command on **PowerShell**.
|
2020-10-25 05:11:40 -07:00
|
|
|
|
Even with `–noprofile` it's noticeably slower compared to `sh`. It's advised to look at using
|
2022-08-23 07:47:55 -07:00
|
|
|
|
[environment variables][env] when using PowerShell.
|
2020-10-25 05:11:40 -07:00
|
|
|
|
:::
|
|
|
|
|
|
2020-10-05 02:33:12 -07:00
|
|
|
|
Command allows you run an arbitrary shell command. Be aware it spawn a new process to fetch the result, meaning
|
2020-10-25 05:11:40 -07:00
|
|
|
|
it will not be able to fetch session based context (look at abusing [environment variables][env] for that).
|
|
|
|
|
When the command errors or returns an empty string, this segment isn't rendered.
|
2020-10-05 02:33:12 -07:00
|
|
|
|
|
|
|
|
|
You have the ability to use `||` or `&&` to stitch commands together and achieve complex results. When using `||`
|
|
|
|
|
the first command that returns a string will be used (or none when they all fail to produce output that's not an
|
|
|
|
|
error). The `&&` functionality will join the output of the commands when successful.
|
|
|
|
|
|
|
|
|
|
## Sample Configuration
|
|
|
|
|
|
2023-03-31 11:55:36 -07:00
|
|
|
|
import Config from '@site/src/components/Config.js';
|
|
|
|
|
|
|
|
|
|
<Config data={{
|
2020-10-05 02:33:12 -07:00
|
|
|
|
"type": "prompt",
|
|
|
|
|
"alignment": "right",
|
|
|
|
|
"segments": [
|
|
|
|
|
{
|
|
|
|
|
"type": "command",
|
|
|
|
|
"style": "plain",
|
|
|
|
|
"foreground": "#ffffff",
|
|
|
|
|
"properties": {
|
|
|
|
|
"shell": "bash",
|
2022-09-09 11:44:52 -07:00
|
|
|
|
"command": "git log --pretty=format:%cr -1 || date +%H:%M:%S"
|
2020-10-05 02:33:12 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-03-31 11:55:36 -07:00
|
|
|
|
}}/>
|
2020-10-05 02:33:12 -07:00
|
|
|
|
|
|
|
|
|
## Properties
|
|
|
|
|
|
2022-09-16 07:32:48 -07:00
|
|
|
|
| Name | Type | Description |
|
|
|
|
|
| --------- | -------- | --------------------------------------------------------------------------------- |
|
|
|
|
|
| `shell` | `string` | the shell in which to run the command in. Uses `shell -c command` under the hood. |
|
|
|
|
|
| `command` | `string` | the command(s) to run |
|
|
|
|
|
| `script` | `string` | the path to a script to run |
|
2020-10-25 05:11:40 -07:00
|
|
|
|
|
2022-02-01 03:10:46 -08:00
|
|
|
|
## Template ([info][templates])
|
|
|
|
|
|
|
|
|
|
:::note default template
|
|
|
|
|
|
2022-09-16 07:32:48 -07:00
|
|
|
|
```template
|
2022-02-01 03:10:46 -08:00
|
|
|
|
{{ .Output }}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
### Properties
|
2022-01-22 10:46:56 -08:00
|
|
|
|
|
2022-12-06 09:48:06 -08:00
|
|
|
|
| Name | Type | Description |
|
|
|
|
|
| ------- | ------ | ---------------------------------- |
|
2022-09-16 07:32:48 -07:00
|
|
|
|
|`.Output`|`string`|the output of the command or script.|
|
2022-01-22 10:46:56 -08:00
|
|
|
|
|
2022-04-20 09:43:59 -07:00
|
|
|
|
[env]: /docs/configuration/templates#environment-variables
|
|
|
|
|
[templates]: /docs/configuration/templates
|