Discussion:
close cygwin window - bash doesnt save history
Shane Brooks
2002-07-10 11:51:27 UTC
Permalink
I've been using cygwin for a while now on Windows 2000 and now Windows
XP - I have updated to the latest version of Cygwin.

If I type "logout", the BASH history is saved and the window closes.

If I close the cygwin window by hitting the 'X' button in the windows titlebar
the Bash History is not saved though I wish it was. - is there a solution to
this minor annoyance?

Shane



--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Barry Buchbinder
2002-07-10 13:29:52 UTC
Permalink
Solution: Don't hit the 'X' button. Don't get out of
bash by turn off the power, either. Use "logout" or
"exit".

Bash obviously does not save history after each
command; it saves history when it shuts down. Hitting
the 'X' button kills it without going through the
normal shut down sequence.

- Barry

-----Original Message-----
From: Shane Brooks [mailto:***@litepc.com]
Sent: Wednesday, July 10, 2002 7:51 am
To: ***@cygwin.com
Subject: close cygwin window - bash doesnt save
history

I've been using cygwin for a while now on Windows 2000
and now Windows
XP - I have updated to the latest version of Cygwin.

If I type "logout", the BASH history is saved and the
window closes.

If I close the cygwin window by hitting the 'X' button
in the windows titlebar
the Bash History is not saved though I wish it was. -
is there a solution to
this minor annoyance?

Shane


__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Dario Alcocer
2002-07-10 15:17:50 UTC
Permalink
Post by Barry Buchbinder
Solution: Don't hit the 'X' button. Don't get out of
bash by turn off the power, either. Use "logout" or
"exit".
Bash obviously does not save history after each
command; it saves history when it shuts down. Hitting
the 'X' button kills it without going through the
normal shut down sequence.
Even better solution: register a signal handler in your Bash session
for SIGHUP; the cygwin1.dll sends a hangup signal when CTRL_CLOSE_EVENT
is received. Something like this:

$ myclosefn() {
echo "My close func got called." > $HOME/myclosefn.txt
# TODO: add more clean-up logic here
}
$ trap myclosefn SIGHUP

I've tested this, so I know it works.

P.S. BTW, I didn't know the answer to this beforehand, but instead
actually looked at the source. That's one of the beauties of open
source projects: questions like these can be answered by direct
inspection. "Read the Source, Luke!" ;-)
--
Dario Alcocer -- Sr. Software Developer, Helix Digital Inc.
***@helixdigital.com -- http://www.helixdigital.com

--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Shane Brooks
2002-07-11 06:26:01 UTC
Permalink
----- Original Message -----
From: Dario Alcocer <***@helixdigital.com>
Date: Wed, 10 Jul 2002 08:17:50 -0700
To: ***@cygwin.com
Subject: Re: close cygwin window - bash doesnt save history
Post by Dario Alcocer
Even better solution: register a signal handler in your Bash session
for SIGHUP; the cygwin1.dll sends a hangup signal when CTRL_CLOSE_EVENT
$ myclosefn() {
echo "My close func got called." > $HOME/myclosefn.txt
# TODO: add more clean-up logic here
}
$ trap myclosefn SIGHUP
I've tested this, so I know it works.
sounds great but perhaps I dont understand the answer - I'm not a programmer or unix boy. I tried typing the following in a bash session but it didnt execute the exit statement when I closed the window.

$ myclosefn() {
Post by Dario Alcocer
exit
}
$ trap myclosefn SIGHUP

I guess Im hoping to find something I can put in my profile or bashrc that will behave as above to automagically perform the "exit" and save the history.
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Save up to $160 by signing up for NetZero Platinum Internet service.
http://www.netzero.net/?refcd=N2P0602NEP8


--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Dario Alcocer
2002-07-11 15:37:22 UTC
Permalink
This post might be inappropriate. Click to display it.
Randall R Schulz
2002-07-11 15:48:54 UTC
Permalink
Shane, Dario,

I was happy to see this suggestion. I'm going to begin using it immediately.

As to those who suggested "don't do that," I have to say ordinarily I avoid
the close box exactly because I lose my history, but accidents (mis-clicks)
happen--sometimes when I really want what's in the as-yet unsaved history
(crashes happen then, too...).


First, Shane, this does exactly what you want, if I understand you
correctly. As you say, put it in you ".bash_profile" or ".login" (whichever
you use or prefer to use). I recommend that you do _not_ put it in you
.bashrc, since that will apply to all invocations of BASH, not just the
top-level "login" ones.

You may need to use the "--login" option when invoking the top-level bash,
to make sure it sources your ".login" file. You should read the BASH manual
about the exact details of startup processing and how the various options
(--login, -i, etc.) and the presence of the various pertinent files
interact. It's kind of messy, if you ask me, though of course you did not...


Dario, in investigating why Shane might not be having success with your
technique, I tried it both with and without the presence of the "tty"
option in the CYGWIN environment variable. (Without is my preferred
operating mode.) I discovered that the SIGHUP handler is _not invoked_ when
the "tty" option _is_ used. (My hypothesis had been the opposite,
actually.) I assume this means that the SIGHUP itself is not delivered when
the close box is clicked and "tty" mode is in effect.

By the way, I did this testing with BASH running in a "console" (character
subsystem) window, not RXVT.

I don't know if this is a bug or intended behavior, but it is what I see
with the latest Cygwin:

CYGWIN_NT-5.0 CLEMENS 1.3.12(0.54/3/2) 2002-07-06 02:16 i686 unknown


Randall Schulz
Mountain View, CA USA
Post by Shane Brooks
----- Original Message -----
Date: Wed, 10 Jul 2002 08:17:50 -0700
Subject: Re: close cygwin window - bash doesnt save history
Post by Dario Alcocer
Even better solution: register a signal handler in your Bash session
for SIGHUP; the cygwin1.dll sends a hangup signal when CTRL_CLOSE_EVENT
$ myclosefn() {
echo "My close func got called." > $HOME/myclosefn.txt
# TODO: add more clean-up logic here
}
$ trap myclosefn SIGHUP
I've tested this, so I know it works.
sounds great but perhaps I dont understand the answer - I'm not a
programmer or unix boy. I tried typing the following in a bash session
but it didnt execute the exit statement when I closed the window.
$ myclosefn() {
Post by Dario Alcocer
exit
}
$ trap myclosefn SIGHUP
I guess Im hoping to find something I can put in my profile or bashrc that
will behave as above to automagically perform the "exit" and save the history.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Dario Alcocer
2002-07-11 16:00:54 UTC
Permalink
Post by Randall R Schulz
Dario, in investigating why Shane might not be having success with your
technique, I tried it both with and without the presence of the "tty"
option in the CYGWIN environment variable. (Without is my preferred
operating mode.) I discovered that the SIGHUP handler is _not invoked_ when
the "tty" option _is_ used. (My hypothesis had been the opposite,
actually.) I assume this means that the SIGHUP itself is not delivered when
the close box is clicked and "tty" mode is in effect.
I'd say try putting the logout command in your SIGHUP handler and
see if it behaves any differently.
--
Dario Alcocer -- Sr. Software Developer, Helix Digital Inc.
***@helixdigital.com -- http://www.helixdigital.com

--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Randall R Schulz
2002-07-11 16:42:41 UTC
Permalink
Dario,

It works great for me just as you suggested (*). I don't like using "tty"
mode, so there's no issue for me. I was thinking perhaps it didn't work for
Shane because he might be using "tty" mode.

However, if the SIGHUP doesn't get delivered (in "tty" mode), there's
really no hook to hang this technique upon, it seems.


(*) In further investigating options using "trap," I discovered I can no
longer repeat my earlier success, regardless of whether I use "tty" or not.

There's something odd afoot here. When and if I figure out more, I'll
report back.

Randall Schulz
Mountain View, CA USA
Post by Dario Alcocer
Post by Randall R Schulz
Dario, in investigating why Shane might not be having success with your
technique, I tried it both with and without the presence of the "tty"
option in the CYGWIN environment variable. (Without is my preferred
operating mode.) I discovered that the SIGHUP handler is _not invoked_
when
Post by Randall R Schulz
the "tty" option _is_ used. (My hypothesis had been the opposite,
actually.) I assume this means that the SIGHUP itself is not delivered
when
Post by Randall R Schulz
the close box is clicked and "tty" mode is in effect.
I'd say try putting the logout command in your SIGHUP handler and
see if it behaves any differently.
--
Dario Alcocer
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Schaible, Jorg
2002-07-11 09:48:54 UTC
Permalink
Hi Shane,
Post by Shane Brooks
If I close the cygwin window by hitting the 'X' button in the
windows titlebar
the Bash History is not saved though I wish it was. - is there
a solution to
this minor annoyance?
don't use the X button, just type CTRL-D.

Regards,
Jorg

--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Shane Brooks
2002-07-13 01:45:39 UTC
Permalink
This post might be inappropriate. Click to display it.
Dario Alcocer
2002-07-13 12:43:54 UTC
Permalink
I couln't agree with you more. I have read the bash man pages several times over though I dont understand it all...
[snip]
Believe me - we aren't all newbies looking for a quick lazy fix - but at some stage we *are* all newbies.
I dont have the TTY env var set...but thats another thread.
Still tryin'
Have you tried logout in the SIGHUP handler? I just tried the following
on my installation, and the history is saved when I click the close
button:

$ myclosefn() {
logout
}
$ trap myclosefn SIGHUP

I tested this by double-clicking the "Cygwin" icon, entering the
commands above, and clicking the close button. Once I double-click
the Cygwin icon again, doing a 'history | tail' will show the
commands above.
--
Dario Alcocer -- Sr. Software Developer, Helix Digital Inc.
***@helixdigital.com -- http://www.helixdigital.com

--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Shane Brooks
2002-07-13 02:13:52 UTC
Permalink
Post by Randall R Schulz
(*) In further investigating options using "trap," I discovered I can no
longer repeat my earlier success, regardless of whether I use "tty" or not.
I used "history -a" , but it appears the trap is being called when the window closes as I can call "myclosefn" OK. I have been typing this at the BASH command prompt, not editing a .bash_login or profile. So my session looks like..

***@GUINNESS ~
$ myclose () {
Post by Randall R Schulz
history -a
}
***@GUINNESS ~
$ trap myclosefn SIGHUP

***@GUINNESS ~
$

using shopt I see that the builtin command huponexit is OFF, but that should be OK shouldnt it? the man page suggests huponexit allows tasks that are not in the job table to recieve the SIGHUP also.

from the man page "When Bash receives a signal for which a trap has been set while waiting for a command to complete, the trap will not be executed until the command completes." - perhaps under windows its too late once the command has completed? ie the window is already closed?

Interestingly I see something flash onto the command line just before the window closes..but my machine is too fast to allow me to read it.
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Save up to $160 by signing up for NetZero Platinum Internet service.
http://www.netzero.net/?refcd=N2P0602NEP8


--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Randall R Schulz
2002-07-13 03:43:40 UTC
Permalink
Shane,

I don't think "huponexit" should have any effect on whether this technique
works.

My guess at what you see flash by is the diagnostic that "myclosefn" cannot
be found (you defined "myclose" and set "myclosefn" as the trap action!).


I still can't make this work. Did I hallucinate that first success?

What I _do_ think is that SIGHUP is not generated when a BASH console
window is closed.

I tried it running in RXVT. It does a whole different funky thing: When I
close the window, the trapped function is executed in an infinite loop and
BASH never exits. This _is_ repeatable.

I just as baffled as before, if not more so.

Randall Schulz
Mountain View, CA USA
Post by Shane Brooks
Post by Randall R Schulz
(*) In further investigating options using "trap," I discovered I can no
longer repeat my earlier success, regardless of whether I use "tty" or not.
I used "history -a" , but it appears the trap is being called when the
window closes as I can call "myclosefn" OK. I have been typing this at
the BASH command prompt, not editing a .bash_login or profile. So my
session looks like..
$ myclose () {
Post by Randall R Schulz
history -a
}
$ trap myclosefn SIGHUP
$
using shopt I see that the builtin command huponexit is OFF, but that
should be OK shouldnt it? the man page suggests huponexit allows tasks
that are not in the job table to recieve the SIGHUP also.
from the man page "When Bash receives a signal for which a trap has been
set while waiting for a command to complete, the trap will not be executed
until the command completes." - perhaps under windows its too late once
the command has completed? ie the window is already closed?
Interestingly I see something flash onto the command line just before the
window closes..but my machine is too fast to allow me to read it.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
Loading...