Dne 12. 04. 23 v 17:40 stan via devel napsal(a):
On Wed, 12 Apr 2023 10:39:44 +0200
Vít Ondruch <vondr...@redhat.com> wrote:

Dne 11. 04. 23 v 18:02 stan via devel napsal(a):
I have the following defined in .bashrc:

# this logs the history explicitly before exiting a shell
hx ()
{
    history -a;
    exit;
}

It means that I have to exit using the command hx when closing a
terminal.

What about using `~/.bash_logout` to avoid the need of `hx`?
I had to do some research to even understand what you were asking.


Sorry, I am not expert in this field. The discussion just caught my attention and that was result of my very brief research.


With that caveat, it seems that a .bash_logout only executes on login
shells.  So, it would not save the history of terminals in X when they
were closed.  Am I misunderstanding?

I did find something that might work in that case, at this link.

https://superuser.com/questions/410525/explain-why-bash-logout-wont-run-commands/410534#410534

"""
~/.bash_logout is only run if it you explicitly exit the shell with
exit or logout, or by typing Control-D to enter an end-of-file at the
command prompt. If you close the terminal emulator, processes are sent
SIGHUP, and bash doesn’t run ~/.bash_logout in that case.

If you want to perform work any time bash exits (and whether it’s a
login shell or not), use trap foo EXIT. The most convenient way to do
this is to put your code in a shell function, e.g.,:

print_goodbye () { echo Goodbye; }
trap print_goodbye EXIT
"""


Interesting. Thx for the link.



Typing exit or logout is more keystrokes than hx, so .bash_logout is not
really compelling.


Ctrl+D is what I am using all the time. That is probably less keystrokes then `hx`, because you save the pressing the Enter ;)


Vít



  The trap looks promising, I assume that I would put
save_history_on_exit () {history -a;}
trap save_history_on_exit EXIT
in .bashrc.  Basically, running a .bash_logout in a different way.

Thanks.
_______________________________________________
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to