ConEmu icon indicating copy to clipboard operation
ConEmu copied to clipboard

Tab doesn't close after exiting Cygwin Bash

Open gene-pavlovsky opened this issue 4 years ago • 5 comments

Versions

ConEmu build: 210912 x64 OS version: Windows 10 Pro x64 Used shell version (Far Manager, git-bash, cmd, powershell, cygwin, whatever): cygwin bash

Problem description

After exiting bash (using Ctrl+D or exit command) the tab never closes. The word "exit" printed by bash on exit is visible, the caret keeps blinking on the next line. A middle-click on the tab closes it without showing any confirmation dialog.

Steps to reproduce

  1. Install Cygwin
  2. Create Bash task Name: Bash Parameters: /dir "%CD%" Task: %ConEmuDrive%\cygwin\bin\conemu-cyg-64.exe bash.exe -new_console:n:C:"%ConEmuDrive%\cygwin\Cygwin.ico":m:/mnt
  3. Run Bash
  4. Exit with Ctrl+D or by executing exit

Actual results

Bash exits, but the tab stays open

Expected results

Tab should close

gene-pavlovsky avatar Dec 04 '21 21:12 gene-pavlovsky

If the tab does not close, that means it has running processes. Check them here: https://conemu.github.io/en/SettingsInfo.html

And I guess you run bash without connector: https://conemu.github.io/en/CygwinMsysConnector.html

Maximus5 avatar Dec 10 '21 12:12 Maximus5

I will check later today regarding the processes. I am using the connector (conemu-cyg-64.exe), you can see it in my Task, mentioned in step 2 of steps to reproduce

gene-pavlovsky avatar Dec 10 '21 12:12 gene-pavlovsky

Screenshots of the Setting dialog and ConEmu window might help.

Maximus5 avatar Dec 10 '21 12:12 Maximus5

So the culprit is ssh-pageant

I'm running it from my bash profile file, as recommended in it's README:

Edit your ~/.bashrc (or ~/.bash_profile) to add the following: eval $(/usr/bin/ssh-pageant -r -a "/tmp/.ssh-pageant-$USERNAME")

The -r option means reuse, so that only one ssh-pageant daemon is running at a time. So if I open several tabs with bash, all of them except the first one will be closable normally (the tab will close). The first tab has the ssh-pageant daemon running, and I guess it's attached to the console. Is there a way to run it detached from the console? Or perhaps I should set it up to run on user login via Task Scheduler or some other mechanism. Suggestions?

Screenshots: 2021-12-11 10_54_03-Settings  xml  ConEmu 210912  64  {Stable} 2021-12-11 10_54_43-Settings  xml  ConEmu 210912  64  {Stable}

gene-pavlovsky avatar Dec 11 '21 10:12 gene-pavlovsky

I've solved the problem. Using the Local Group Policy Editor, I have created a Logon script (actually, quite a while ago). Script name: C:\cygwin\bin\run.exe Script parameters: cmd.exe /c C:\usr\etc\rc.d\logon.cmd

logon.cmd:

@echo off
set Path=C:\cygwin\bin:%Path%

bash /etc/init.d/local start

The local script is omitted as it's not really important, it just runs multiple sub-scripts located in /etc/local.d, the relevant one for ssh-pageant is:

#!/bin/sh
SSH_AUTH_SOCK="/home/$USERNAME/.ssh-pageant-auth-sock"
setx SSH_AUTH_SOCK "${SSH_AUTH_SOCK}"
setsid /usr/bin/ssh-pageant -r -a "${SSH_AUTH_SOCK}" &>/dev/null

This way, ssh-pageant is started at user logon, and when I run Far or bash in ConEmu, they already have the correct SSH_AUTH_SOCK variable, and everything works great. My ssh keys are stored in a KeePassXC database, KeePassXC adds them to Pageant, when I unlock the database, and ssh-pageant allows Cygwin programs (git, ssh) to use those keys transparently. I've removed eval $(/usr/bin/ssh-pageant -r -a "/tmp/.ssh-pageant-$USERNAME") from my bash_profile as it's not needed anymore.

I guess this issue can be closed?

gene-pavlovsky avatar Dec 11 '21 12:12 gene-pavlovsky