Allow wt.exe to close tabs via command line argument #20277

Closed
opened 2026-01-31 07:08:48 +00:00 by claunia · 3 comments
Owner

Originally created by @bzm3r on GitHub (Jul 23, 2023).

Description of the new feature/enhancement

Currently, we can open new tabs using wt newtab.

However, we cannot close existing tabs via the command line.

Can such a command line argument be provided?

Originally created by @bzm3r on GitHub (Jul 23, 2023). # Description of the new feature/enhancement Currently, we can open new tabs using `wt newtab`. However, we cannot close existing tabs via the command line. Can such a command line argument be provided?
Author
Owner

@carlos-zamora commented on GitHub (Jul 26, 2023):

Hi @bzm3r. We're hesitant to add this kind of functionality because it could be used maliciously. Curious though, why do you want this feature?

@carlos-zamora commented on GitHub (Jul 26, 2023): Hi @bzm3r. We're hesitant to add this kind of functionality because it could be used maliciously. Curious though, why do you want this feature?
Author
Owner

@bzm3r commented on GitHub (Jul 26, 2023):

Hi @bzm3r. We're hesitant to add this kind of functionality because it could be used maliciously. Curious though, why do you want this feature?

Just because it's cleaner than killing a window, and re-opening it? I'm not sure I understand why this is a maliciousness issue, when it is possible to kill a terminal window quite easily, and/or any shells that are running in tabs (e.g. PowerShell's Stop-Process)?

@bzm3r commented on GitHub (Jul 26, 2023): > Hi @bzm3r. We're hesitant to add this kind of functionality because it could be used maliciously. Curious though, why do you want this feature? Just because it's cleaner than killing a window, and re-opening it? I'm not sure I understand why this is a maliciousness issue, when it is possible to kill a terminal window quite easily, and/or any shells that are running in tabs (e.g. PowerShell's `Stop-Process`)?
Author
Owner

@stianhoiland commented on GitHub (Apr 14, 2025):

I'm requesting this issue reopened. I'm wanting this functionality as well: close pane, close tab, and close window command line arguments.

My use case is tight integration between the terminal emulator and the shell. I use Windows Terminal sort of like how people use tmux. It is great to be able to open new panes with custom commands from within terminal apps. Without close commands, I'm limited in the kinds of interactions I can set up. For example, I cannot create a new Windows Terminal pane from within my editor to show some information (say compiler output) and then close the pane again with another command/hotkey from within my editor.

Here are some straightforward shell functions I use to control my workspace:

new() {
  if [[ "$#" -eq 0 ]]
  then
    wt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'"
  else
    wt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*"
  fi
}
tab() {
  if [[ "$#" -eq 0 ]]
  then
    wt -w last nt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'"
  else
    wt -w last nt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*"
  fi
}
# TODO Redo these to take a "down, up, left, right" arg
split() { # stacks
  if [[ "$#" -eq 0 ]]
  then
    wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'"
  else
    wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*"
  fi
}
splitdown() {
  if [[ "$#" -eq 0 ]]
  then
    wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD'"
  else
    wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD' && $*"
  fi
}
splitup() {
  if [[ "$#" -eq 0 ]]
  then
    wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD'" && wt -w last swap-pane previousInOrder
  else
    wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD' && $*" && wt -w last swap-pane previousInOrder
  fi
}
splitfocus() {
  if [[ "$#" -eq 0 ]]
  then
    wt -w last sp -p "$WT_PROFILE_ID" -H --size 0.3 "$(which busybox)" sh -sc "source ~/.profile && cd '$(realpath "$PWD")'" && wt -w last mf previousInOrder
  else
    wt -w last sp -p "$WT_PROFILE_ID" -H --size 0.3 "$(which busybox)" sh -sc "source ~/.profile && cd '$(realpath "$PWD")' && $*" && wt -w last mf previousInOrder
  fi
}

At the moment I'm experimenting with the following kludge to provide at least some semblance of this functionality, and from which you can glean @bzm3r's argument that if you want to tamper with a process launched by the terminal, lacking a convenient and hygienic way of doing so isn't gonna stop a malicious actor. It leaves the pane dangling (and the process dead) according to the "Profile termination behavior" setting.

wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "echo \$$ > '$TMP/split.$$.pid' && cd '$PWD'" && sleep 0.2 && kill $(cat "$TMP/split.$$.pid") # sleep 0.14 will sometimes be too quick
@stianhoiland commented on GitHub (Apr 14, 2025): I'm requesting this issue reopened. I'm wanting this functionality as well: close pane, close tab, and close window command line arguments. My use case is tight integration between the terminal emulator and the shell. I use Windows Terminal sort of like how people use tmux. It is great to be able to open new panes with custom commands from within terminal apps. Without close commands, I'm limited in the kinds of interactions I can set up. For example, I cannot create a new Windows Terminal pane from within my editor to show some information (say compiler output) and then close the pane again with another command/hotkey from within my editor. Here are some straightforward shell functions I use to control my workspace: ```sh new() { if [[ "$#" -eq 0 ]] then wt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'" else wt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*" fi } tab() { if [[ "$#" -eq 0 ]] then wt -w last nt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'" else wt -w last nt -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*" fi } # TODO Redo these to take a "down, up, left, right" arg split() { # stacks if [[ "$#" -eq 0 ]] then wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD'" else wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "cd '$PWD' && $*" fi } splitdown() { if [[ "$#" -eq 0 ]] then wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD'" else wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD' && $*" fi } splitup() { if [[ "$#" -eq 0 ]] then wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD'" && wt -w last swap-pane previousInOrder else wt -w last sp -p "$WT_PROFILE_ID" -H "$(which busybox)" sh -lsc "cd '$PWD' && $*" && wt -w last swap-pane previousInOrder fi } splitfocus() { if [[ "$#" -eq 0 ]] then wt -w last sp -p "$WT_PROFILE_ID" -H --size 0.3 "$(which busybox)" sh -sc "source ~/.profile && cd '$(realpath "$PWD")'" && wt -w last mf previousInOrder else wt -w last sp -p "$WT_PROFILE_ID" -H --size 0.3 "$(which busybox)" sh -sc "source ~/.profile && cd '$(realpath "$PWD")' && $*" && wt -w last mf previousInOrder fi } ``` At the moment I'm experimenting with the following kludge to provide at least some semblance of this functionality, and from which you can glean @bzm3r's argument that if you want to tamper with a process launched by the terminal, lacking a convenient and hygienic way of doing so isn't gonna stop a malicious actor. It leaves the pane dangling (and the process dead) according to the "Profile termination behavior" setting. ```sh wt -w last sp -p "$WT_PROFILE_ID" "$(which busybox)" sh -lsc "echo \$$ > '$TMP/split.$$.pid' && cd '$PWD'" && sleep 0.2 && kill $(cat "$TMP/split.$$.pid") # sleep 0.14 will sometimes be too quick ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20277