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

Implement showing of git branch in the prompt #67

Merged
merged 3 commits into from
Sep 7, 2024

Conversation

certik
Copy link
Collaborator

@certik certik commented Sep 7, 2024

We keep track of if we are inside a git repository inside the ShellState struct as well as if the branch was updated in the last command. In the main loop we then update the branch name if it wasn't already updated, and then show the branch in the prompt if we are inside a repository.

We only visit .git/HEAD once per set_cwd() call and we only run again in the main loop if we did not run in that iteration yet.

However I discovered that the set_cwd() call is being called twice in every iteration for some reason (#76), and so we also read .git/HEAD twice. This is a separate issue so it should be fixed in a separate PR once this is merged.

@certik certik requested a review from wolfv September 7, 2024 20:35
We keep track of if we are inside a git repository inside the ShellState
struct as well as if the branch was updated in the last command. In the main
loop we then update the branch name if it wasn't already updated, and then show
the branch in the prompt if we are inside a repository.

We only visit `.git/HEAD` once per `set_cwd()` call and we only run again in
the main loop if we did not run in that iteration yet.

However I discovered that the `set_cwd()` call is being called twice in every
iteration for some reason, and so we also read `.git/HEAD` twice. This is a
separate issue so it should be fixed in a separate PR once this is merged.
@certik
Copy link
Collaborator Author

certik commented Sep 7, 2024

@wolfv this is ready.

@wolfv
Copy link
Member

wolfv commented Sep 7, 2024

Cool! I am fine with merging this, but I think for the future we should come up with e.g. a notification system where you could register functions that should run "on cwd change".

Because this is pretty specific and only useful in the interactive shell mode.

@wolfv
Copy link
Member

wolfv commented Sep 7, 2024

@prsabahrami also OK with merging for now?

@wolfv
Copy link
Member

wolfv commented Sep 7, 2024

Maybe one thing we could do is create a new struct for all the Git related stuff. So that it's bundled in one object inside the shell state.

@prsabahrami
Copy link
Collaborator

This looks good to me. But I also agree with @wolfv on creating a separate struct for git stuff. I think it makes more sense.

@wolfv wolfv merged commit 73cf8fb into prefix-dev:main Sep 7, 2024
4 checks passed
@wolfv
Copy link
Member

wolfv commented Sep 7, 2024

Let's merge for now, and refactor later! :)

@wolfv
Copy link
Member

wolfv commented Sep 7, 2024

I already started to depend on the functionality haha

@certik
Copy link
Collaborator Author

certik commented Sep 8, 2024

Thanks. I created #74 for the refactoring.

@certik certik mentioned this pull request Sep 8, 2024
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.

3 participants