Ctrl+W doesn't terminate shells properly (so they can't do teardown and cleanup things) #2769

Closed
opened 2026-01-30 23:04:36 +00:00 by claunia · 13 comments
Owner

Originally created by @axfelix on GitHub (Jul 15, 2019).

Environment

Windows build number: Microsoft Windows [Version 10.0.18917.1000]
Windows Terminal version (if applicable): 0.2.1831.0

Steps to reproduce

Exit a mingw bash shell using a keyboard shortcut to close the tab

Expected behavior

exit is sent to the shell, process is terminated, if closing a running process the user is warned

Actual behavior

Terminal is detached and not killed

Originally created by @axfelix on GitHub (Jul 15, 2019). # Environment Windows build number: Microsoft Windows [Version 10.0.18917.1000] Windows Terminal version (if applicable): 0.2.1831.0 # Steps to reproduce Exit a mingw bash shell using a keyboard shortcut to close the tab # Expected behavior `exit` is sent to the shell, process is terminated, if closing a running process the user is warned # Actual behavior Terminal is detached and not killed
claunia added the Help WantedIssue-BugNeeds-Tag-FixProduct-TerminalArea-Interop labels 2026-01-30 23:04:36 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jul 15, 2019):

Maybe we need to consider having an exitCommand setting? Though, what would happen if you launched a process from bash where exit did not exit the program? For example, vim. How would we determine when to send exit to the commandline application?

@zadjii-msft commented on GitHub (Jul 15, 2019): Maybe we need to consider having an `exitCommand` setting? Though, what would happen if you launched a process from bash where `exit` did _not_ exit the program? For example, `vim`. How would we determine when to send `exit` to the commandline application?
Author
Owner

@axfelix commented on GitHub (Jul 15, 2019):

Most terminal apps I've used on other platforms will warn when pressing Ctrl+W if anything else is running, on the assumption that the user probably doesn't want to kill the shell after all, and if they really do then probably all bets are off (you could send Ctrl+C then exit but that's a much less predictable use case anyway).

@axfelix commented on GitHub (Jul 15, 2019): Most terminal apps I've used on other platforms will warn when pressing Ctrl+W if anything else is running, on the assumption that the user probably doesn't want to kill the shell after all, and if they really do then probably all bets are off (you could send Ctrl+C then exit but that's a much less predictable use case anyway).
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 15, 2019):

This is absolutely a bug, we shouldn't go and add a new "command to send on exit". That's probably not a winning strategy.

We constrain our shells into job objects, so they should absolutely be getting terminated when the tab is closed.

@DHowett-MSFT commented on GitHub (Jul 15, 2019): This is absolutely a bug, we shouldn't go and add a new "command to send on exit". That's probably not a winning strategy. We constrain our shells into job objects, so they _should_ absolutely be getting terminated when the tab is closed.
Author
Owner

@wuss912 commented on GitHub (Oct 25, 2019):

CTRL + W is also used in a number of curses based apps... need a way to disable it as a kill switch so it can pass through instead

@wuss912 commented on GitHub (Oct 25, 2019): CTRL + W is also used in a number of curses based apps... need a way to disable it as a kill switch so it can pass through instead
Author
Owner

@axfelix commented on GitHub (Oct 25, 2019):

yup, that's why Mac has separation between Ctrl and Cmd, and Linux terminals use Ctrl+Shift for any terminal window shortcuts so that Ctrl shortcuts can be sent directly to the term. Not sure if you want to adopt that convention here too.

@axfelix commented on GitHub (Oct 25, 2019): yup, that's why Mac has separation between Ctrl and Cmd, and Linux terminals use Ctrl+Shift for any terminal window shortcuts so that Ctrl shortcuts can be sent directly to the term. Not sure if you want to adopt that convention here too.
Author
Owner

@tats-u commented on GitHub (Oct 29, 2019):

Ctrl+Shift+W must be used to close the terminal instead.

Ctrl + W -> Split, Toggle, or something else panes (with alphabetic keys) in Vim, or Cut selected text or Write current file (with Ctrl +X) in Emacs
Ctrl + C -> Quit current application
Ctrl + V -> Start selecting text in Vim or PageDown in Emacs

@tats-u commented on GitHub (Oct 29, 2019): Ctrl+Shift+W must be used to close the terminal instead. Ctrl + W -> Split, Toggle, or something else panes (with alphabetic keys) in Vim, or Cut selected text or Write current file (with Ctrl +X) in Emacs Ctrl + C -> Quit current application Ctrl + V -> Start selecting text in Vim or PageDown in Emacs
Author
Owner

@shtirlic commented on GitHub (Jan 29, 2020):

+1 to exitCommand
I use terminal with docker desktop, running as default ENV for development, every new tab started with command like docker start -ti dev_env zsh, so when I close the tab, I would like to send exit 0 to the zsh process, and then tab will be closed since exit code is 0.

@shtirlic commented on GitHub (Jan 29, 2020): +1 to `exitCommand ` I use terminal with docker desktop, running as default ENV for development, every new tab started with command like `docker start -ti dev_env zsh`, so when I close the tab, I would like to send `exit 0` to the zsh process, and then tab will be closed since exit code is 0.
Author
Owner

@shtirlic commented on GitHub (Mar 18, 2020):

Also update I can autoclose background zsh process with setting TMOUT env for idle timeout as workaround but it's not good because when you leave tabs open it's closes after TMOUT time, since there is no SIGALRM handling.

@shtirlic commented on GitHub (Mar 18, 2020): Also update I can autoclose background zsh process with setting TMOUT env for idle timeout as workaround but it's not good because when you leave tabs open it's closes after TMOUT time, since there is no SIGALRM handling.
Author
Owner

@fprimex commented on GitHub (Dec 10, 2020):

I was editing in vim and using :vert sp when I discovered this behavior trying to change between splits. There should be an option or default behavior to not close the window with Ctrl+W. On non-mac systems, as @tats-u mentioned, ctrl+shift+w is the keyboard shortcut for window closing.

I feel like this is perhaps a separate issue from not cleaning up the shells. If that's the case I can open a new issue.

@fprimex commented on GitHub (Dec 10, 2020): I was editing in vim and using `:vert sp` when I discovered this behavior trying to change between splits. There should be an option or default behavior to not close the window with Ctrl+W. On non-mac systems, as @tats-u mentioned, ctrl+shift+w is the keyboard shortcut for window closing. I feel like this is perhaps a separate issue from not cleaning up the shells. If that's the case I can open a new issue.
Author
Owner

@DHowett commented on GitHub (Dec 10, 2020):

Hey @fprimex! Thanks for sticking with us since version 0.2! We actually changed the default for all new users to have closePane bound to ctrl+shift+w back in v0.3, in July 2019.

It might be a good time to refresh your settings file! Back up the bindings and profiles you care about, delete the file, and let Terminal make a new one. Things have changed a lot since the default was ctrl+w for that action. 😄

@DHowett commented on GitHub (Dec 10, 2020): Hey @fprimex! Thanks for sticking with us since version 0.2! We actually changed the default for all new users to have `closePane` bound to `ctrl+shift+w` back in v0.3, in July 2019. It might be a good time to refresh your settings file! Back up the bindings and profiles you care about, delete the file, and let Terminal make a new one. Things have changed _a lot_ since the default was `ctrl+w` for that action. :smile:
Author
Owner

@fprimex commented on GitHub (Dec 10, 2020):

Hmm. This is a fresh install from the app store on a recently new-to-me machine that I only got in the past month. All I have changes are the prev & next tab bindings. I will review everything & see if I went wrong somewhere doing the install.

@fprimex commented on GitHub (Dec 10, 2020): Hmm. This is a fresh install from the app store on a recently new-to-me machine that I only got in the past month. All I have changes are the prev & next tab bindings. I will review everything & see if I went wrong somewhere doing the install.
Author
Owner

@fprimex commented on GitHub (Dec 10, 2020):

Alrighty, seems fine. Not sure where I went wrong. Maybe I managed to fat finger across ctrl and shift twice earlier lol. Thanks!

@fprimex commented on GitHub (Dec 10, 2020): Alrighty, seems fine. Not sure where I went wrong. Maybe I managed to fat finger across ctrl and shift twice earlier lol. Thanks!
Author
Owner

@axfelix commented on GitHub (Dec 17, 2020):

This seems to be working now -- I think I'll close this issue. Thanks!

@axfelix commented on GitHub (Dec 17, 2020): This seems to be working now -- I think I'll close this issue. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2769