You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, as I mentioned in previous issue #147 I'm recording bash history in a custom way. As of now, I'm trying to save the command (and current directory) to a file using preexec. Can I use precmd to keep duration and exit code of the command and then also save them?
Actually, is it possible for preexec() to keep the command as variable and then pass it to precmd as input? In that case precmd() has everything (i.e. command, folder, duration, exit code) to save to a log file.
The text was updated successfully, but these errors were encountered:
I don't remember if it's possible to pass variables between the two, but when I wanted to do something similar, I decided to separately log when the command began and when it ended. With timestamps, so the duration can be calculated. That way if the command crashed the shell or the system, or caused the disk to run out of space, there would still be a chance that the command was logged before it started running. In case it's useful to you, here's the code I use to log shell commands with preexec and precmd: https://github.com/dseomn/dotfiles/blob/598a37a20bf5c413e634119efd8f8f922571fc60/.config/shell/interactive.d/50-history.bash#L56-L101
Here's an example of capturing duration and exit code via the preexec/precmd hooks (this example actually uses the PROMPT_COMMAND and DEBUG trap directly by default, but if bash-preexec is found in the shell environment it delegates to bash-preexec instead).
Hi, as I mentioned in previous issue #147 I'm recording bash history in a custom way. As of now, I'm trying to save the command (and current directory) to a file using
preexec
. Can I useprecmd
to keep duration and exit code of the command and then also save them?Actually, is it possible for
preexec()
to keep the command as variable and then pass it toprecmd
as input? In that caseprecmd()
has everything (i.e. command, folder, duration, exit code) to save to a log file.The text was updated successfully, but these errors were encountered: