Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: option to relaunch a profile when it exits #4379

Closed
tatroc opened this issue Jan 28, 2020 · 13 comments · Fixed by #14060
Closed

Feature Request: option to relaunch a profile when it exits #4379

tatroc opened this issue Jan 28, 2020 · 13 comments · Fixed by #14060
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@tatroc
Copy link

tatroc commented Jan 28, 2020

If I have a ssh.exe session open to another machine using ssh.exe (Openssh) and I disconnect from the network the session hangs in the Windows Terminal. I must close the tab. Could we make the session resume by pressing enter? Or is there a better way to handle this?

{
"guid": "{5f77e6d6-8215-45d0-be70-a277c72accf6}",
"hidden": false,
"name": "user@host",
"commandline": "ssh.exe user@host",
"fontFace": "Consolas",
"fontSize": 12,
"icon": "%USERPROFILE%\AppData\Local\lxss\bash.ico"
},

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 28, 2020
@DHowett-MSFT
Copy link
Contributor

Thanks for the request! I've triaged it and converted it into a request to relaunch a profile when it exits.

@DHowett-MSFT DHowett-MSFT changed the title Windows terminal tab hangs after network connectivity lost Feature Request: option to relaunch a profile when it exits Jan 31, 2020
@DHowett-MSFT DHowett-MSFT added Area-Settings Issues related to settings and customizability, for console or terminal Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jan 31, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jan 31, 2020
@DHowett-MSFT DHowett-MSFT added this to the Terminal v1.x milestone Jan 31, 2020
@DHowett-MSFT
Copy link
Contributor

For now, you can relaunch a new copy of that profile with ctrl+shift+d (duplicateTab)

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Dec 29, 2020

Would relaunching the profile preserve the screen buffer, window title, and WT_SESSION environment variable?

@zadjii-msft
Copy link
Member

From #4772: It might be nice if this was an enum value for closeOnExit. Something like "reconnect" to automatically reconnect (or reconnect after prompting for enter or something) to re-spawn the connection.

There's also #3726 for "manually restart a connection", which is similar, but different.

@thernstig
Copy link

thernstig commented May 11, 2021

I wrote a duplicate for this (which I have now closed) that might contain some more context: #10075 But in short, this happens all the time when in hibernation or on bad Wifi, and I want to preserve my screen buffer etc. to continue where I left of.

One solution would be to display some text at the bottom of the buffer similar to how like done here in the April 2021 release of VS Code: https://code.visualstudio.com/updates/v1_56#_untitled-editors-hint. So a Press Enter to relaunch shell might be an option.

But I also do like the closeOnExit: "reconnect" as an added thing for users.

@masics
Copy link

masics commented Aug 12, 2021

We need to reconnect in the same tab.

  • It will keep the order of the tabs
  • No need to close the original tab manually
  • It will keep the screen buffer

@SteffenBlake
Copy link

I have created a very simple little powershell script one can utilize to sort of replicate this behavior.

Save the following script to: C:\Windows\System32\Keep-Alive.ps1

$command=$args[0]

while ($TRUE) {
    Invoke-Expression $command
    Start-Sleep -Seconds 1
    Write-Output "Scope ended. Press Enter to reload."
    Read-Host
}

Then you can put your SSH or whatnot call nested within this function call to loop it on exit.

For example I put the following as my command for my profile's Command Line field:

PowerShell Keep-Alive 'ssh rancher@Usagi -i \"C:\Users\MyName\Documents\SSH Keys\Usagi\Usagi.pem\"'

Then you get something like the following:

image

@swinder0161
Copy link

Highly needed feature for the reasons mentioned above.
Comparison: iterm2 for mac has this feature and would be great we have in windows terminal too.

WT is great but can be even better and the greatest terminal emulator out there.

@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@zadjii-msft zadjii-msft removed this from the Backlog milestone Jan 18, 2022
@zadjii-msft zadjii-msft added this to the Up Next milestone Jan 18, 2022
@sisrfeng
Copy link

sisrfeng commented Feb 16, 2022

modified from above :

  1. create a file called C:\Windows\System32\leo_keep.ps1
$leo_command=$args[0]

while ($TRUE) {
    Invoke-Expression $leo_command
    Start-Sleep -Seconds 1
    Write-Output "leo: ssh disconnected,  Press Enter to reload."
    Read-Host
}
  1. use PowerShell leo_keep 'ssh -X you@yourip' instead of 'ssh -X you@yourip at windows terminal' s profile

Set-ExecutionPolicy -ExecutionPolicy unrestricted

image

I think it is not that unsafe to use unrestricted
image


About Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass:

image

@swinder0161
Copy link

In wt profile use: wt_ssh.bat 192.168.1.100

modify ssh %1 to you command. No need of powershell to execute it. No policy change needed.

n followed by enter will terminate and exit
any other key followed by enter or simply press enter to reconnect.

wt_ssh.bat

@echo off

:START
ssh %1

echo.

set /a reconnect=y
set /p reconnect="ssh connection terminated, do you want to reconnect(Y/n)?"
rem echo reconnect: %reconnect%

echo.

if %reconnect%==n (echo exit) else (goto START)

@IBNobody
Copy link

In wt profile use: wt_ssh.bat 192.168.1.100

modify ssh %1 to you command. No need of powershell to execute it. No policy change needed.

n followed by enter will terminate and exit any other key followed by enter or simply press enter to reconnect.

wt_ssh.bat

@echo off

:START
ssh %1

echo.

set /a reconnect=y
set /p reconnect="ssh connection terminated, do you want to reconnect(Y/n)?"
rem echo reconnect: %reconnect%

echo.

if %reconnect%==n (echo exit) else (goto START)

Change ssh %1 to ssh %*. Some of us need ssh with extra switches.

@EBADBEEF
Copy link

I would also like this feature but if anyone else stumbles here like I did here is my one-liner workaround.

Automatically restart ssh in a loop: cmd /C for /L %i in (0,0,1) do @ssh user@host
Add a sleep in the loop: cmd /C "for /L %i in (0,0,1) do @ssh user@host & timeout /T 2"
Add a command to ssh (for me, reattach tmux): cmd /C "for /L %i in (0,0,1) do @ssh user@host -t . ~/.bashrc; my-tmux-bash-function %COMPUTERNAME% & timeout /T 2"

I couldn't figure out how to use '&' in the ssh command because windows cmd/for will interpret that. There is probably a way to escape it.

@ghost ghost added the In-PR This issue has a related PR label Sep 23, 2022
@ghost ghost closed this as completed in #14060 Dec 8, 2022
@ghost ghost closed this as completed in c0e4689 Dec 8, 2022
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Dec 8, 2022
@ghost
Copy link

ghost commented Jan 24, 2023

🎉This issue was addressed in #14060, which has now been successfully released as Windows Terminal Preview v1.17.1023.:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.