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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xonsh support #1375

Merged
merged 17 commits into from
Jan 29, 2024
Merged

Add xonsh support #1375

merged 17 commits into from
Jan 29, 2024

Conversation

Matthieu-LAURENT39
Copy link
Contributor

This PR aims to add support for Xonsh to atuin.

Copy link

vercel bot commented Nov 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
atuin-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 10:05pm

Copy link
Collaborator

@conradludgate conradludgate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was quick. I guess xonsh has no mechanism for altering the ctrl-R keybindings?

@Matthieu-LAURENT39
Copy link
Contributor Author

Matthieu-LAURENT39 commented Nov 5, 2023

This PR is blocked while i wait for a reply from the xonsh community.
It seems that xonsh doesn't have a way to source the output of commands, as it doesn't have an eval command (and the eval and evalx functions as well as the @$() syntax don't work, they are unable to execute most instructions).
Therefore, the output of atuin init xonsh would have to be written to a temporary file, then sourced, which is far from ideal.
I'm waiting to get an answer on whether or not before there is a workaround before continuing, which might take a while as xonsh's matrix channel seems quite inactive.

That was quick. I guess xonsh has no mechanism for altering the ctrl-R keybindings?

I couldn't find any at the very least

@arcuru
Copy link
Sponsor Contributor

arcuru commented Nov 6, 2023

Therefore, the output of atuin init xonsh would have to be written to a temporary file, then sourced, which is far from ideal.

We already need to do that for nushell, so it's annoying but not that odd - https://atuin.sh/docs/advanced-install#nushell

I think the keybindings can be set using the prompt_toolkit? - https://xon.sh/tutorial_ptk.html

@Matthieu-LAURENT39
Copy link
Contributor Author

In that case, i'll use a temp file for now.
As for the prompt toolkit, it does look like it's the proper thing to use, thanks for the info!

@jfmontanaro
Copy link
Contributor

What's the status of this PR? I have been working getting atuin to work with my xonsh install and wound up with something fairly similar, except that I'm using subprocess directly to run the atuin search because doing it as a regular xonsh shell command results in a broken buffer state after it returns (e.g. for whatever reason you can't navigate left/right with arrow keys until you've either run the command or ctrl-c'd out.)

I'd be happy to contribute changes to this PR, or submit a new one if @Matthieu-LAURENT39 would prefer.

@Matthieu-LAURENT39
Copy link
Contributor Author

Matthieu-LAURENT39 commented Jan 12, 2024

I didn't have time to work on this PR lately, so feel free to add improvements to it!

Otherwise i was planning on continuing it next week or the week after that, there isn't much left to be done.

@jfmontanaro
Copy link
Contributor

jfmontanaro commented Jan 15, 2024

Followup question for the atuin maintainers: I'm working on history importers for xonsh to go with this (there are multiple importers because, like zsh and nushell, xonsh has an alternate mode that stores history in a sqlite db.) I have two questions:

  1. Xonsh has a concept of a "session id" much like atuin does, except that xonsh uses UUIDv4's while atuin uses UUIDv7's. Can I import history entries with the xonsh session id, or does atuin rely on e.g. the orderability of UUIDv7's for something?
  2. Xonsh doesn't store the hostname of where a command was run, but it also doesn't have any kind of history-syncing built in. Is it reasonable to just assume that all commands in the history were run on the current device? Or is it too likely that e.g. people have set up their own syncing solutions that would break that assumption? (I notice none of the existing importers do this for hostnames, so maybe it's already been determined that it's preferable to leave it blank in this situation.)

@ellie
Copy link
Member

ellie commented Jan 17, 2024

Can I import history entries with the xonsh session id, or does atuin rely on e.g. the orderability of UUIDv7's for something?

We don't rely on it! It's purely for index performance. I'd prefer if you could generate a new UUIDv7 if possible, though if not the Xonsh ID is also OK

Is it reasonable to just assume that all commands in the history were run on the current device?

This would be reasonable! If we don't have the information then there is little that can be done.

Matthieu-LAURENT39 and others added 10 commits January 18, 2024 09:36
Summary of changes:
* Added duration to postcommand hook
* Switched main search operation to use `subproccess.run()` rather than running as an xonsh shell command - this a) allows us to capture stderr without needing a temporary file and b) avoids a weird broken-buffer state that results from running a fullscreen TUI and then programmatically editing the buffer
* Added support for immediately executing chosen command via `__atuin_accept__:` (like bash/zsh/fish)
@Matthieu-LAURENT39
Copy link
Contributor Author

@jfmontanaro do you have anything else you want to add, or should i mark the PR as ready for review?

@jfmontanaro
Copy link
Contributor

I think you can go ahead and mark it ready. I am working on functionality for importing xonsh history, but I think I'll just open another PR for that later.

Xonsh doesn't import private functions into the local namespace when sourcing a file
@Matthieu-LAURENT39
Copy link
Contributor Author

I'm adding support for ATUIN_NOBIND, but there's one thing i'm not sure about.
Do we check for that variable every time ctrl+r or up arrow is pressed, or only once during generation with atuin init xonsh?

@Matthieu-LAURENT39
Copy link
Contributor Author

In the end, i went with what it seems to do for bash, aka only check once during the initial sourcing, and not checking again afterwards.

Anyways, that's all i wanted to add, this should be ready for review!

@Matthieu-LAURENT39 Matthieu-LAURENT39 marked this pull request as ready for review January 24, 2024 20:54
Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand of Xonsh (not much), looks great! Thank you both 🙏

Would one of you also be able to update the docs please? 🙏

Seeing as this is your first time contributing, if you would like a holographic contributors-only Atuin sticker, then please fill out this form!

We do also have a Discord if you'd like to ask any questions, or just fancy hanging out!

@Matthieu-LAURENT39
Copy link
Contributor Author

Matthieu-LAURENT39 commented Jan 29, 2024

I have some free time, i'll try to make a PR to add some documentation 👍

ellie pushed a commit to atuinsh/docs that referenced this pull request Jan 29, 2024
This adds xonsh-related informations to the docs.
Related PR: atuinsh/atuin#1375
@ellie ellie merged commit c56f8ff into atuinsh:main Jan 29, 2024
7 of 8 checks passed
@anki-code
Copy link

anki-code commented Jan 29, 2024

@ellie please take a look #1659

@anki-code
Copy link

anki-code commented Jan 29, 2024

Guys from this PR - you rock! Thank you! 🎉

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

Successfully merging this pull request may close these issues.

6 participants