-
-
Notifications
You must be signed in to change notification settings - Fork 809
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 option to abbreviate based path based on the git root #720
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkeithhill having tried this :/
I'm hesitating a bit.
:/
is supposed to be the root,:/myproject/src
is incorrect based on this convention- maybe
myproject:/src
or[myproject]:/src
would 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two edge cases to consider here:
- If the current repo is bare, this returns its parent directory.
Get-GitDirectory
inside 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-GitDirectory
to return the contents of.git/worktrees/[name]/gitdir
. No idea what the downstream effects of this would be. - Check here if
$gitPath
matches.git/worktrees/
; if it does, set$gitPath
to the contents of$gitPath/gitdir
- Revise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: