-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
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.
@wolfv this is ready. |
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. |
@prsabahrami also OK with merging for now? |
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. |
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. |
Let's merge for now, and refactor later! :) |
I already started to depend on the functionality haha |
Thanks. I created #74 for the refactoring. |
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 perset_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.