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

Question: Can we make PS1 async? #18

Open
felippemr opened this issue Jun 3, 2020 · 14 comments
Open

Question: Can we make PS1 async? #18

felippemr opened this issue Jun 3, 2020 · 14 comments

Comments

@felippemr
Copy link

It might be a stretch but things would be way smoother.

@jD91mZM2
Copy link
Owner

What are you thinking? Like use an alternate prompt until powerline-rs is done?

@felippemr
Copy link
Author

I don't know but, it seems that if we could make PS1 somehow be loaded asynchronously the responsiveness of the shell could be improved. It is not an issue with this project though. FYI, I recently stopped showing git info on my powerline because it was not responsive, I wanted it to be faster so now I am using gitmux to show the info on my tmux window. Since it is not part of PS1, my terminal does not hang while powerline is building my PS1.

Thanks for the great work of putting this together!

@moderation
Copy link

I've also found the git integration slow with powerline-rs. I've tried updating the git2 dependency to to the latest 0.13.6 but haven't noticed any appreciable difference - https://github.com/jD91mZM2/powerline-rs/blob/master/Cargo.toml#L29. The biggest slowdown is on large complex repos like https://github.com/envoyproxy/envoy

@jD91mZM2
Copy link
Owner

Yes, git2 seems to be incredibly slow at large repos, not sure why :(

@moderation
Copy link

Looks like the underlying libgit2 is the issue - https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+slow

@jD91mZM2
Copy link
Owner

Yes, precisely why I've not been able to fix it

@jD91mZM2
Copy link
Owner

Seems like changes are on their way! libgit2/libgit2#4230 :)

@moderation
Copy link

Unfortunately that issue has been open for years but little forward motion. I've been trying to work out how to pull in the fork that has better performance.

https://crates.io/crates/git2 pulls in https://crates.io/crates/libgit2-sys as a dependency. From that crates repo https://github.com/rust-lang/git2-rs#version-of-libgit2

The source for libgit2 is included in the libgit2-sys crate so there's no need to pre-install the libgit2 library, the libgit2-sys crate will figure that and/or build that for you.

It looks like https://github.com/rust-lang/git2-rs/tree/master/libgit2-sys then pulls in the libgit2 library pinned to https://github.com/libgit2/libgit2/tree/86b85492b1bc8eeb9ff1af25b92877969f17833a

So maybe I should attempt to fork libgit2-sys to point to the higher performance fork at https://github.com/romkatv/libgit2 somehow?

@jD91mZM2
Copy link
Owner

jD91mZM2 commented Jun 27, 2020

It looks like https://github.com/rust-lang/git2-rs/tree/master/libgit2-sys then pulls in the libgit2 library pinned to https://github.com/libgit2/libgit2/tree/86b85492b1bc8eeb9ff1af25b92877969f17833a

So maybe I should attempt to fork libgit2-sys to point to the higher performance fork at https://github.com/romkatv/libgit2 somehow?

Good work digging through! Let me help you with that last bit: Yes, you could update the submodule for sure. Using [patch] sections in Cargo.toml, you can recursively override libraries of your choice from any binary. But it seems like you can also just install the libgit2 fork on your system, and git2-rs will recognize that it doesn't need to compile the code itself :) source

@lafleurdeboum
Copy link
Contributor

As a workaround, in zsh I use powerline-rs without git status on PROMPT, and the git status in RPROMPT asynchronously with the following snippet in ~/.zshrc :

# Remove the trailing space in RPROMPT. Used for compat
# with older terminals that would span a newline.
ZLE_RPROMPT_INDENT=0

# Async solution found at https://unix.stackexchange.com/a/645949 :
async_rprompt_callback() {
    RPROMPT="$(<&$1)"
    zle reset-prompt
    zle -F $1
}

async_rprompt() {
    # At first tell the current permissions in rprompt.
    RPROMPT="$(powerline-rs --rtl --shell zsh --modules perms)"

    # Then asynchronously check the git details.
    exec {FD}< <(
        powerline-rs --rtl --shell zsh --modules perms,git,gitstage
    )

    zle -F $FD async_rprompt_callback
}

powerline_prompt() {
    PROMPT="$(powerline-rs --shell zsh --cwd-max-depth 2 --modules ssh,host,cwd,root $?)"
    async_rprompt
    # Let terminals display working dir :
    echo -en "\e]2;${PWD/$HOME/~}\a"
}

if $(which powerline-rs); then
    precmd_functions+=(powerline_prompt)
else
    # call your alternative prompt here
fi

It's a bit verbose but it works like a charm - I was able to use it when compiling the linux kernel over and over (huge git repo).

@ThisNekoGuy
Copy link

Is... this going to get an update?

@Artturin
Copy link

Is... this going to get an update?

jD91mZM2 has passed away https://www.redox-os.org/news/open-source-mental-health/

@ThisNekoGuy
Copy link

Oh, wait, I knew about this; I hadn't realized it was the same guy - that was a little while ago...
Ugh, I feel bad 🤦‍♂️

@lafleurdeboum
Copy link
Contributor

lafleurdeboum commented Nov 5, 2022 via email

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

6 participants