-
-
Notifications
You must be signed in to change notification settings - Fork 955
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 SPACESHIP_DIR_TRUNC_PREFIX, a prefix before cwd when truncated #281
Add SPACESHIP_DIR_TRUNC_PREFIX, a prefix before cwd when truncated #281
Conversation
Thanks for PR. Let's do not include this feature in |
sections/dir.zsh
Outdated
@@ -11,6 +11,7 @@ SPACESHIP_DIR_SHOW="${SPACESHIP_DIR_SHOW:=true}" | |||
SPACESHIP_DIR_PREFIX="${SPACESHIP_DIR_PREFIX:="in "}" | |||
SPACESHIP_DIR_SUFFIX="${SPACESHIP_DIR_SUFFIX:="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}" | |||
SPACESHIP_DIR_TRUNC="${SPACESHIP_DIR_TRUNC:=3}" | |||
SPACESHIP_DIR_TRUNC_PREFIX="${SPACESHIP_DIR_TRUNC_PREFIX:=.../}" |
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.
Just not to forget, when you rebase on latest 3.0
this line should become SPACESHIP_DIR_TRUNC_PREFIX="${SPACESHIP_DIR_TRUNC_PREFIX=".../"}"
5ec9250
to
4b6bd19
Compare
4b6bd19
to
cdae11d
Compare
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.
I've been using this patch since it was created and I love it!
Fixes #343 |
cdae11d
to
c2b4400
Compare
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.
Looks good. Would be great with some comments.
sections/dir.zsh
Outdated
dir="$git_root:t${$(expr $(pwd) : "$git_root\(.*\)")}" | ||
|
||
if [[ $git_root:h == / ]]; then | ||
trunc_prefix=/ |
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.
If I understand correctly, This checks whether the git_root
is /
, Right ? But why would someone keep /
under git
!! 😕
Or did I miss something ?
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.
This checks whether the parent of git_root
is /
. For strange people who keep their repos directly under the root (I'm not doing that personally).
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.
Sorry I missed that :h
modifier. Not judging anyone, Still it feels kinda weird to store repositories directly under root.
sections/dir.zsh
Outdated
trunc_prefix=$SPACESHIP_DIR_TRUNC_PREFIX | ||
fi | ||
|
||
dir="$trunc_prefix$git_root:t${PWD#$~~git_root}" |
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 is sorcery 🦄, Would be great if you could leave some comments.
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 looks wonderful @segevfiner 👏
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.
Looks like #385 affects this too. Could you please take a look @segevfiner ?
sections/dir.zsh
Outdated
# `$~~` avoids `GLOB_SUBST` so that `$git_root` won't actually be | ||
# considered a pattern and matched literally, even if someone turns that on. | ||
# See "Parameter Expansion" under the Zsh manual. | ||
dir="$trunc_prefix$git_root:t${PWD#$~~git_root}" |
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.
This causes symlinked directories to appear twice.
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.
This is because $git_root
has symlinks resolved. Guess I can use the working directory with symlinks resolved here. Hopefully that's the desired behavior.
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.
Awesome, Hope we can merge this long standing PR soon with one more approval.
Thank you for quick response 👍
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.
I already approved this earlier, looks good 👍
26ed7fd
to
62d654c
Compare
Sorry I didn't pay attention to this PR for a long time. My point on this: I don't like the idea of cluttering prompt with BTW, instead of using |
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.
Please, consider my comments.
@denysdovhan I wasn't sure originally whether to use the Unicode ellipsis ( In terms of whether to enable this by default or not, I guess that's up to you. Maybe @maximbaz @salmanulfarzy want to pitch in? The facility to disable it is already there, you simply set SPACESHIP_DIR_TRUNC_PREFIX="" I added some more documentation so that even if you choose to disable it the user still has examples for how to enable it, or on the other hand, disable it. |
Whatever gets this PR finally merged 🙂 I personally find this feature very intuitive and I use it, but I don't mind enabling it locally if it's disabled by default. |
I prefer it disabled by default for |
There is currently only an option to enable or disable it for both outside and inside a repo. I guess it can be split into two separate options, though I think that makes is slightly more complex for users to enable/disable. I will start at least by setting it to disabled by default, since that appears to be the consensus. Hopefully the instructions I left on how to enable it are enough. |
1cf9638
to
cf27766
Compare
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.
Please resolve the conflict.
cf27766
to
193e407
Compare
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.
👍
Just wanted to ask if there are any updates on this or anything blocking the PR from being merged? |
|
sections/dir.zsh
Outdated
@@ -21,14 +22,36 @@ SPACESHIP_DIR_COLOR="${SPACESHIP_DIR_COLOR="cyan"}" | |||
spaceship_dir() { | |||
[[ $SPACESHIP_DIR_SHOW == false ]] && return | |||
|
|||
local dir | |||
local dir trunc_prefix | |||
|
|||
# Threat repo root as a top-level directory or not | |||
if [[ $SPACESHIP_DIR_TRUNC_REPO == true ]] && spaceship::is_git; then | |||
local git_root=${$(git rev-parse --absolute-git-dir):h} |
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.
This change has been reverted on the current master. Because this requires at least git v2.13.0
. Because --absolute-git-dir
was added with that release.
I see, thanks, I just came here because of #343 (for which there is a workaround). If the main reason for holding off the PR is to avoid possible breaking changes, I would perhaps look into pulling #384 since that seems more innocuous. My two cents about the default behavior: I like |
When the cwd is truncated by SPACESHIP_DIR_TRUNC instead of showing: a/b/c It will show: .../a/b/c The prefix is configurable of course and can be disabled by setting it to an empty string. I also modified SPACESHIP_DIR_TRUNC_REPO to use SPACESHIP_DIR_TRUNC_PREFIX and made it not truncate on a repository that is below the root directory. In addition, I optimized its code to use Zsh constructs instead of command substitutions.
193e407
to
c5456d2
Compare
Rebased. |
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.
Manually tested with Zsh 5.4.2
ang git 2.17.0
I'm approving this PR with the above results. Let's see whether there is any regression on other version of Zsh
and git
.
@salmanulfarzy #417 should fix the ".git directory" case. |
A version of #280 for the 3.0 branch
When the cwd is truncated by
SPACESHIP_DIR_TRUNC
instead of showing:It will show:
The prefix is configurable of course and can be disabled by setting it to an empty string.
I also modified
SPACESHIP_DIR_TRUNC_REPO
to useSPACESHIP_DIR_TRUNC_PREFIX
and made it not truncate for a repository that is below the root directory. In addition, I optimized its code to use Zsh constructs instead of command substitutions.cc @maximbaz
Fixes #343