Add option to abbreviate based path based on the git root#720
Add option to abbreviate based path based on the git root#720rkeithhill merged 6 commits intodahlbyk:masterfrom
Conversation
3fa372c to
828461b
Compare
|
@dahlbyk @rkeithhill now with tests :) |
src/Utils.ps1
Outdated
| $currentPath.StartsWith($gitPath, $stringComparison)) { | ||
| # Up another level to keep repo name in path | ||
| $removePath = $(Split-Path $gitPath -Parent) | ||
| $currentPath = "-" + $currentPath.SubString($removePath.Length) |
There was a problem hiding this comment.
Hmm, what character should be used to indicate the rooted in the Git repo? I could see some folks wanting to use $/ as opposed to -/. Or maybe ./ or even an emoji. I wind up replacing ~ with 🏠. I might be tempted to use 🎪 or 💩for the root of Git repos. :-)
There was a problem hiding this comment.
Fair enough, -/ is no convention.
OMG apparently :/ is the git convention for the repository root! https://stackoverflow.com/a/22049939/27219
Additionally would you suggest adding a new configuration option like $GitPromptSettings.DefaultPromptGitRootPrefix?
There was a problem hiding this comment.
Cool. Let's go with that then. How about we call it DefaultPromptGitDirectoryRootPrefix to try to tie it a bit closer to the other setting?
There was a problem hiding this comment.
@rkeithhill having tried this :/ I'm hesitating a bit.
:/is supposed to be the root,:/myproject/srcis incorrect based on this convention- maybe
myproject:/srcor[myproject]:/srcwould be more correct?
Using a function (passing project name and sub-path) would allow to format that the way people want.
There was a problem hiding this comment.
That seems reasonable. Of course, whether it's reponame:\ or reponame:/ will depend on the platform.
Using a function (passing project name and sub-path) would allow to format that the way people want.
What do you mean? Keep in mind folks can already do this:
$GitPromptSettings.DefaultPromptPath.Text = '$(CallMyCustomPromptFunction)'
There was a problem hiding this comment.
Good point about the directory separator direction!
And you're right - one may as well just replace the function.
All fixed, but I didn't add any option for the : as it sounds like we are using a correct convention
|
@elsassph Thanks! |
|
@rkeithhill I stumbled onto something more about the colon: So it sounds like it should be adjusted before being worth releasing and maybe this would be a better formatting: |
| if ($abbrevGitDir) { | ||
| $gitPath = Get-GitDirectory | ||
| # Up one level from `.git` | ||
| if ($gitPath) { $gitPath = Split-Path $gitPath -Parent } |
There was a problem hiding this comment.
Two edge cases to consider here:
- If the current repo is bare, this returns its parent directory.
Get-GitDirectoryinside a worktree currently returns the path to.git/worktrees/[name], which won't match the current path. I can think of two ways to resolve this:- Revise
Get-GitDirectoryto return the contents of.git/worktrees/[name]/gitdir. No idea what the downstream effects of this would be. - Check here if
$gitPathmatches.git/worktrees/; if it does, set$gitPathto the contents of$gitPath/gitdir
- Revise
There was a problem hiding this comment.
Never used worktrees, but git abbreviation just won't happen in that case.
An issue should be created to track it.
There was a problem hiding this comment.
Never used worktrees, but git abbreviation just won't happen in that case.
Not a problem. It doesn't break, it just won't work as expected in all cases.
An issue should be created to track it.


Implement #719. Added an option to abbreviate the prompt path based on the git root.
When enabled
When the currentpath is under a git repository, e.g.
Prompt shows a path shortened to: