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 a variable for showing repo name #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paulaltin
Copy link

I find that when working with multiple repositories – or especially with git submodules – it can be useful to see in the prompt which one I'm currently in. (This will often be the current working directory, but not always.)

@AaronDMarasco-VSI
Copy link

IMHO this is kind of useless; it uses the local file system to assume that you checked it out in a way that matches the repo name. Personally, I almost never do that.

I think it would be much more useful if it used this instead:
basename "$(git config --local remote.origin.url)" .git

(The quotes are if, for some reason I can't think of, they undefined 'origin'; it will return blank.)

@paulaltin
Copy link
Author

paulaltin commented Apr 24, 2019

Hi @AaronDMarasco-VSI, thanks for looking at this.

I guess everyone has their own way of using Git. Personally, I always check out repositories using git clone so the local directory name does match, but my remote isn't always called "origin".

However, we should be able to make it robust to both use cases. How about something like this:

if repo=$(git config --local remote.origin.url 2> /dev/null); then
    git_repo="($(basename "$repo" .git))"
elif repo=$(git rev-parse --show-toplevel 2> /dev/null); then
    git_repo="($(basename "$repo"))"
else
    git_repo=""
fi

@AaronDMarasco-VSI
Copy link

@paulaltin that sounds good to me if you add some inline comments to each concerning what you're trying to compute (I know rev-parse is kinda esoteric).

That said, I'm just a bystander here; I have no special privs on this repo.

@paulaltin
Copy link
Author

OK, I've updated it and added some inline comments. Thanks for your input @AaronDMarasco-VSI

@7urkm3n
Copy link

7urkm3n commented Jun 26, 2019

@paulaltin No need it, if repo name is huge then its gonna annoy. Ignore, nor add into alternate preferences, do not suggest it to make it default.

Default:
Yes! PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
No! PROMPT_COMMAND="find_git_repo; find_git_branch; find_git_dirty; $PROMPT_COMMAND"

@lethosor
Copy link
Contributor

find_git_repo just makes the variable available. It doesn't put it in your prompt. Leaving it in PROMPT_COMMAND is reasonable if you ask me; it's likely much faster than find_git_dirty.

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.

4 participants