Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate shell commands to used files #1980

Open
tycho-kirchner opened this issue Apr 26, 2024 · 2 comments
Open

Associate shell commands to used files #1980

tycho-kirchner opened this issue Apr 26, 2024 · 2 comments

Comments

@tycho-kirchner
Copy link

Hi,
a friend of mine has just shared a link to this project which is closely related to my own (a bit less popular and sophisticated 馃檪) shournal, but lacks a feature important for researchers: tracing of files (see our paper Bashing irreproducibility with shournal). shournal allows you to ask for a specific file, with what particular command it was created or how it was used based on tracing deep down in the Linux kernel. So I kindly wanted to ask you to whether you are interested in adding such a feature to Atuin. For instance the kernel module backend is controllable via a single c-header file that you may want to integrate for that purpose.

In any case regarding bash, you may consider replacing bash-preexec by PS0 (search here for _shournal_ps0 for an example).

Thanks and kind regards
Tycho

@tycho-kirchner tycho-kirchner changed the title Associate shell command to used files Associate shell commands to used files Apr 26, 2024
@akinomyoga
Copy link
Contributor

shournal allows you to ask for a specific file, with what particular command it was created or how it was used based on tracing deep down in the Linux kernel.

Couldn't both Atuin and shournal be independently configured?

In any case regarding bash, you may consider replacing bash-preexec by PS0 (search here for _shournal_ps0 for an example).

Atuin wants to leave a change in the main shell environment, but command substitutions in PS0 cannot do that. Also, PS0 is only supported in bash >= 4.4. I expect Bash 5.3's function substitutions to enable leaving changes, but it hasn't yet been released. Anyway, Atuin doesn't try to implement preexec/precmd but is just using an external framework.

@tycho-kirchner
Copy link
Author

tycho-kirchner commented Apr 29, 2024

Couldn't both Atuin and shournal be independently configured?

Sure! However, shournal hash no sync infrastructure for its history at all and I supposed it might be easier, adding file-tracing to Atuin than adding the sync infrastructure to shournal 馃槈.

Atuin wants to leave a change in the main shell environment, but command substitutions in PS0 cannot do that.

It is possible to set variables in the main shell environment from PS0 using nifty parameter expansion tricks, i.e. incrementing a counter using

${existing_var:((++counter)):0}

Similarly, one can utilize $? from an own function and use the variable in PROMPT_COMMAND, e.g.

existing_var=foo
PS0='$(exit 42)${existing_var:((preexec_ret=$?)):0}'
# .. but in PROMPT_COMMAND preexec_ret has to be emptied
PROMPT_COMMAND='echo preexec_ret: $preexec_ret; preexec_ret="";'

Finally, any code can be executed in the main shell using signals, has I've shown here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants