help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature Request: Timestamp for when a function is defined


From: Chris Elvidge
Subject: Re: Feature Request: Timestamp for when a function is defined
Date: Sun, 16 Mar 2025 12:31:02 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4

On 15/03/2025 at 21:28, Stan Marsh wrote:
I implement a lot of things via (bash) shell functions.
I keep them stored in files in a directory called ~/bash_functions, and I have 
code
in .bash_aliases to load (i.e., source, aka "dot") every file in that directory.
I usually have lots of shells open in various windows (and SSH sessions).
It all works very well, except...

One of the issues I frequently face is that if I edit the function definition, 
then I
need to re-source the file in every shell session, or else that shell will be 
running
an out-of-date version.  This is, of course, a PITA, and there's no good way to 
tell
whether or not you're running an old version.  Now, of course, one approach is 
"When
in doubt, re-source", but that's obviously less than ideal.

Now, what I would like to see is some built-in support for this in bash itself.
At a minimum, it seems to me that if bash would record somewhere a table of 
when each
function was most recently defined, then it should be possible to put code in 
the
function itself to check to see if the file is newer than the "last definition 
time"
and react accordingly.  Even better would be if bash would also record from 
which
file the definition came.

This could be implemented as associative arrays, with the key being the 
function name
and the value being the timestamp (or the filename).




How would that help those of us that keep functions in "normal places" such as /etc/bash_functions and/or /etc/profile.d/NNN-bash-functions.sh and/or ~/.bash_functions?

--
Chris Elvidge
England




reply via email to

[Prev in Thread] Current Thread [Next in Thread]