2020-04-12 02:15:14 +03:00
|
|
|
## Launching Programs
|
|
|
|
|
|
|
|
By default, when opening new tabs or windows, your shell will be spawned.
|
|
|
|
|
|
|
|
Your shell is determined by the following rules:
|
|
|
|
|
|
|
|
### On Posix Systems
|
|
|
|
|
|
|
|
1. The value of the `$SHELL` environment variable is used if it is set
|
|
|
|
2. Otherwise, it will resolve your current uid and try to look up your
|
2022-11-30 19:37:10 +03:00
|
|
|
shell from the password database.
|
2020-04-12 02:15:14 +03:00
|
|
|
|
|
|
|
`wezterm` will spawn the shell and pass `-l` as an argument to request
|
|
|
|
a login shell. A login shell generally loads additional startup files
|
|
|
|
and sets up more environment than a non-login shell.
|
|
|
|
|
2021-05-03 02:13:32 +03:00
|
|
|
*Since: 20210502-154244-3f7122cb*: instead of passing `-l` to the shell, wezterm
|
2021-05-01 17:31:35 +03:00
|
|
|
will spawn the shell as `-$SHELL` to invoke it as a login shell.
|
|
|
|
|
2020-04-12 02:15:14 +03:00
|
|
|
Note: if you have recently changed your shell using `chsh` and you
|
|
|
|
have `$SHELL` set in the environment, you will need to sign out and
|
|
|
|
sign back in again for the environment to pick up your new `$SHELL`
|
|
|
|
value.
|
|
|
|
|
2022-09-04 06:53:46 +03:00
|
|
|
*Since: 20220903-194523-3bb1ed61*: wezterm will now always resolve the shell via the
|
2022-08-31 05:00:05 +03:00
|
|
|
password database.
|
|
|
|
|
2020-04-12 02:15:14 +03:00
|
|
|
### On Windows Systems
|
|
|
|
|
|
|
|
1. The value of the `%COMSPEC%` environment variable is used if it is set.
|
|
|
|
2. Otherwise, `cmd.exe`
|
|
|
|
|
|
|
|
## Changing the default program
|
|
|
|
|
|
|
|
If you'd like `wezterm` to run a different program than the shell as
|
|
|
|
described above, you can use the `default_prog` config setting to specify
|
|
|
|
the argument array; the array allows specifying the program and arguments
|
|
|
|
portably:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
return {
|
|
|
|
-- Spawn a fish shell in login mode
|
2022-07-19 17:54:31 +03:00
|
|
|
default_prog = { '/usr/local/bin/fish', '-l' },
|
2020-04-12 02:15:14 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-04-13 01:09:41 +03:00
|
|
|
## Launching a different program as a one off via the CLI
|
|
|
|
|
|
|
|
If you want to make a shortcut for your desktop environment that will,
|
|
|
|
for example, open an editor in wezterm you can use the `start` subcommand
|
|
|
|
to launch it. This example opens up a new terminal window running vim
|
|
|
|
to edit your wezterm configuration:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
wezterm start -- vim ~/.wezterm.lua
|
|
|
|
```
|
|
|
|
|
2021-01-26 21:40:22 +03:00
|
|
|
## Specifying the current working directory
|
|
|
|
|
|
|
|
If you'd like `wezterm` to start running a program in a specific working
|
|
|
|
directory you can do so via the config, CLI, and when using
|
|
|
|
[`SpawnCommand`](lua/SpawnCommand.md):
|
|
|
|
|
|
|
|
* Setting the [`default_cwd`](lua/config/default_cwd.md) via the config:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
return {
|
|
|
|
default_cwd = "/some/path",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
* One off program in a specific working directory via the CLI:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
wezterm start --cwd /some/path
|
|
|
|
```
|
|
|
|
|
|
|
|
* The [`SpawnCommandInNewTab`](lua/keyassignment/SpawnCommandInNewTab.md),
|
2022-03-09 15:04:19 +03:00
|
|
|
and [`SpawnCommandInNewWindow`](lua/keyassignment/SpawnCommandInNewWindow.md)
|
|
|
|
key assignments, and the [Launcher Menu](#the-launcher-menu) described below
|
|
|
|
all accept a [`SpawnCommand`](lua/SpawnCommand.md) object that accepts an
|
|
|
|
optional `cwd` field:
|
2021-01-26 21:40:22 +03:00
|
|
|
|
|
|
|
```lua
|
|
|
|
{
|
|
|
|
label = "List files in /some/path",
|
|
|
|
args = {"ls", "-al"},
|
|
|
|
cwd = "/some/path",
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Panes/Tabs/Windows created after the first will generally try to resolve the
|
|
|
|
current working directory of the current Pane, preferring
|
2021-01-31 01:14:29 +03:00
|
|
|
[a value set by OSC 7](../shell-integration.md) and falling back to
|
2021-01-26 21:40:22 +03:00
|
|
|
attempting to lookup the `cwd` of the current process group leader attached to a
|
|
|
|
local Pane. If no `cwd` can be resolved, then the `default_cwd` will be used.
|
|
|
|
If `default_cwd` is not specified, then the home directory of the user will be
|
|
|
|
used.
|
|
|
|
|
2021-01-26 23:04:35 +03:00
|
|
|
[See `default_cwd` for an easier to understand visualization](lua/config/default_cwd.md).
|
|
|
|
|
2020-04-12 02:15:14 +03:00
|
|
|
## Passing Environment variables to the spawned program
|
|
|
|
|
|
|
|
The `set_environment_variables` configuration setting can be used to
|
|
|
|
add environment variables to the environment of the spawned program.
|
|
|
|
|
|
|
|
The behavior is to take the environment of the `wezterm` process
|
|
|
|
and then set the specified variables for the spawned process.
|
|
|
|
|
|
|
|
```lua
|
|
|
|
return {
|
|
|
|
set_environment_variables = {
|
|
|
|
-- This changes the default prompt for cmd.exe to report the
|
|
|
|
-- current directory using OSC 7, show the current time and
|
|
|
|
-- the current directory colored in the prompt.
|
2022-07-19 17:54:31 +03:00
|
|
|
prompt = '$E]7;file://localhost/$P$E\\$E[32m$T$E[0m $E[35m$P$E[36m$_$G$E[0m ',
|
2020-04-12 02:15:14 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# The Launcher Menu
|
|
|
|
|
|
|
|
The launcher menu is accessed from the new tab button in the tab bar UI; the
|
2022-01-17 17:36:24 +03:00
|
|
|
`+` button to the right of the tabs. Left clicking on the button will spawn a
|
|
|
|
new tab, but right clicking on it will open the launcher menu. You may also
|
|
|
|
bind a key to the [ShowLauncher](lua/keyassignment/ShowLauncher.md) or
|
|
|
|
[ShowLauncherArgs](lua/keyassignment/ShowLauncherArgs.md) action to trigger the
|
|
|
|
menu.
|
2020-04-12 02:15:14 +03:00
|
|
|
|
|
|
|
The launcher menu by default lists the various multiplexer domains and offers
|
|
|
|
the option of connecting and spawning tabs/windows in those domains.
|
|
|
|
|
2022-01-17 17:36:24 +03:00
|
|
|
You can define your own entries using the
|
|
|
|
[launch_menu](lua/config/launch_menu.md) configuration setting. The snippet
|
|
|
|
below adds two new entries to the menu; one that runs the `top` program to
|
|
|
|
monitor process activity and a second one that explicitly launches the `bash`
|
|
|
|
shell.
|
2020-04-12 02:15:14 +03:00
|
|
|
|
2020-10-10 20:49:36 +03:00
|
|
|
Each entry in `launch_menu` is an instance of a
|
|
|
|
[SpawnCommand](lua/SpawnCommand.md) object.
|
|
|
|
|
2020-04-12 02:15:14 +03:00
|
|
|
```lua
|
|
|
|
return {
|
|
|
|
launch_menu = {
|
|
|
|
{
|
2022-07-19 17:54:31 +03:00
|
|
|
args = { 'top' },
|
2020-04-12 02:15:14 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
-- Optional label to show in the launcher. If omitted, a label
|
|
|
|
-- is derived from the `args`
|
2022-07-19 17:54:31 +03:00
|
|
|
label = 'Bash',
|
2020-04-12 02:15:14 +03:00
|
|
|
-- The argument array to spawn. If omitted the default program
|
|
|
|
-- will be used as described in the documentation above
|
2022-07-19 17:54:31 +03:00
|
|
|
args = { 'bash', '-l' },
|
2020-04-12 02:15:14 +03:00
|
|
|
|
2020-06-03 18:48:37 +03:00
|
|
|
-- You can specify an alternative current working directory;
|
2020-04-12 02:15:14 +03:00
|
|
|
-- if you don't specify one then a default based on the OSC 7
|
|
|
|
-- escape sequence will be used (see the Shell Integration
|
|
|
|
-- docs), falling back to the home directory.
|
|
|
|
-- cwd = "/some/path"
|
|
|
|
|
|
|
|
-- You can override environment variables just for this command
|
|
|
|
-- by setting this here. It has the same semantics as the main
|
|
|
|
-- set_environment_variables configuration option described above
|
|
|
|
-- set_environment_variables = { FOO = "bar" },
|
|
|
|
},
|
2022-07-19 17:54:31 +03:00
|
|
|
},
|
2020-04-12 02:15:14 +03:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="../screenshots/launch-menu.png" alt="Screenshot">
|
|
|
|
|
2020-04-12 18:51:11 +03:00
|
|
|
Here's a fancy example that will add some helpful entries to the launcher
|
|
|
|
menu when running on Windows:
|
|
|
|
|
|
|
|
```lua
|
2022-07-19 17:54:31 +03:00
|
|
|
local wezterm = require 'wezterm'
|
2020-04-12 18:51:11 +03:00
|
|
|
|
|
|
|
local launch_menu = {}
|
|
|
|
|
2022-07-19 17:54:31 +03:00
|
|
|
if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
|
2020-04-12 18:51:11 +03:00
|
|
|
table.insert(launch_menu, {
|
2022-07-19 17:54:31 +03:00
|
|
|
label = 'PowerShell',
|
|
|
|
args = { 'powershell.exe', '-NoLogo' },
|
2020-04-12 18:51:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Find installed visual studio version(s) and add their compilation
|
|
|
|
-- environment command prompts to the menu
|
2022-07-19 17:54:31 +03:00
|
|
|
for _, vsvers in
|
|
|
|
ipairs(
|
|
|
|
wezterm.glob('Microsoft Visual Studio/20*', 'C:/Program Files (x86)')
|
|
|
|
)
|
|
|
|
do
|
|
|
|
local year = vsvers:gsub('Microsoft Visual Studio/', '')
|
2020-04-12 18:51:11 +03:00
|
|
|
table.insert(launch_menu, {
|
2022-07-19 17:54:31 +03:00
|
|
|
label = 'x64 Native Tools VS ' .. year,
|
|
|
|
args = {
|
|
|
|
'cmd.exe',
|
|
|
|
'/k',
|
|
|
|
'C:/Program Files (x86)/'
|
|
|
|
.. vsvers
|
|
|
|
.. '/BuildTools/VC/Auxiliary/Build/vcvars64.bat',
|
|
|
|
},
|
2020-04-12 18:51:11 +03:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
launch_menu = launch_menu,
|
|
|
|
}
|
|
|
|
```
|