Fix git-root Not Working Correctly for Repositories in symlinks & Add Customisation Options #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix git-root With symlinks
Problem
As the title says,
prompt-pwd
would not remove the git root from the current path if the repository was located under a symlink.The problem is caused by the fact that command
git rev-parse --show-toplevel
returns the physical path of the git root, whereas$PWD
contains the symbolic one.Example
➜ /Users/matteoc/iCloud/Code/prompt-pwd master ✓
The repository is located inside a symlinked folder (
iCloud
), and instead of showing justprompt-pwd
it shows the entire physical path.Solution
This was easily fixed by using
pwd -P
instead of$PWD
.Result
➜ prompt-pwd master ✓
The prompt is now printed correctly regardless of whether the repository was reached with a physical or symbolic path.
Consequences
Calling
pwd -P
is slower than using$PWD
directly. I ran the following benchmarks to test it on my system:The actual execution time for the singles cases are:
pwd -P
0.2ms$PWD
0.01msI am using a relatively powerful machine, but even if the script was running on a machine an order of magnitude slower, it would still take a millisecond at most for either
pwd
or$PWD
.