git-aware-prompt icon indicating copy to clipboard operation
git-aware-prompt copied to clipboard

Add a variable for showing repo name

Open paulaltin opened this issue 5 years ago • 6 comments

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.)

paulaltin avatar Apr 17 '19 00:04 paulaltin

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.)

AaronDMarasco-VSI avatar Apr 17 '19 11:04 AaronDMarasco-VSI

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

paulaltin avatar Apr 24 '19 14:04 paulaltin

@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.

AaronDMarasco-VSI avatar Apr 25 '19 10:04 AaronDMarasco-VSI

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

paulaltin avatar Apr 30 '19 08:04 paulaltin

@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"

7urkm3n avatar Jun 26 '19 16:06 7urkm3n

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.

lethosor avatar Jun 26 '19 17:06 lethosor