Skip to content
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

Merged

Conversation

segevfiner
Copy link
Contributor

@segevfiner segevfiner commented Dec 15, 2017

A version of #280 for the 3.0 branch

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 for a repository that is below the root directory. In addition, I optimized its code to use Zsh constructs instead of command substitutions.

image

cc @maximbaz

Fixes #343

@denysdovhan denysdovhan added frozen Progress is temporarily frozen until resolving the specific issue. new-feature A PR that implement feature (section, specific behavior, etc). proposal An issue (rarely PR) for feature-requests, ideas, etc labels Dec 18, 2017
@denysdovhan
Copy link
Member

Thanks for PR. Let's do not include this feature in 3.0. I just don't want to make next major release too complex, because it already takes too much time to make it ready. We can release this later as a minor release after 3.0.

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:=.../}"
Copy link
Contributor

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=".../"}"

maximbaz
maximbaz previously approved these changes Jan 19, 2018
Copy link
Contributor

@maximbaz maximbaz left a 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!

@salmanulfarzy salmanulfarzy removed the frozen Progress is temporarily frozen until resolving the specific issue. label Jan 20, 2018
@segevfiner segevfiner changed the title [3.0] Add SPACESHIP_DIR_TRUNC_PREFIX, a prefix before cwd when truncated Add SPACESHIP_DIR_TRUNC_PREFIX, a prefix before cwd when truncated Jan 21, 2018
@salmanulfarzy
Copy link
Member

salmanulfarzy commented Jan 22, 2018

Fixes #343

Copy link
Member

@salmanulfarzy salmanulfarzy left a 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=/
Copy link
Member

@salmanulfarzy salmanulfarzy Feb 28, 2018

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 ?

Copy link
Contributor Author

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

Copy link
Member

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}"
Copy link
Member

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.

salmanulfarzy
salmanulfarzy previously approved these changes Mar 1, 2018
Copy link
Member

@salmanulfarzy salmanulfarzy left a 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 👏

Copy link
Member

@salmanulfarzy salmanulfarzy left a 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 ?

ls symlink
prompt

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}"
Copy link
Member

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.

Copy link
Contributor Author

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.

salmanulfarzy
salmanulfarzy previously approved these changes Mar 6, 2018
Copy link
Member

@salmanulfarzy salmanulfarzy left a 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 👍

maximbaz
maximbaz previously approved these changes Mar 8, 2018
Copy link
Contributor

@maximbaz maximbaz left a 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 👍

@segevfiner
Copy link
Contributor Author

Re-based due to #385. It was fixed differently here by 62d654c.

@denysdovhan
Copy link
Member

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 .../. I'd like to have it disabled by default. Prompt looks much cleaner without it.

BTW, instead of using ..., we can try , which is much cleaner and shorter.

Copy link
Member

@denysdovhan denysdovhan left a 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.

@segevfiner
Copy link
Contributor Author

@denysdovhan I wasn't sure originally whether to use the Unicode ellipsis (), but since Spaceship already uses other exotic Unicode chars and the Unicode ellipsis is quite older than them it should be OK.

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 to be empty:

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.

@maximbaz
Copy link
Contributor

maximbaz commented Mar 9, 2018

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?

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.

@salmanulfarzy
Copy link
Member

salmanulfarzy commented Mar 9, 2018

I prefer it disabled by default for git directories, giving a cleaner look. But I find prefix to be much useful when current path is longer than SPACESHIP_DIR_TRUC on non-git directories.

@segevfiner
Copy link
Contributor Author

segevfiner commented Mar 10, 2018

I prefer it disabled by default for git directories, giving a cleaner look. But I find prefix to be much useful when current path is longer than SPACESHIP_DIR_TRUC on non-git directories.

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.

salmanulfarzy
salmanulfarzy previously approved these changes Mar 22, 2018
Copy link
Member

@salmanulfarzy salmanulfarzy left a 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.

salmanulfarzy
salmanulfarzy previously approved these changes Mar 24, 2018
Copy link
Member

@salmanulfarzy salmanulfarzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@slhck
Copy link

slhck commented May 3, 2018

Just wanted to ask if there are any updates on this or anything blocking the PR from being merged?

@salmanulfarzy
Copy link
Member

salmanulfarzy commented May 3, 2018

@slhck

Just wanted to ask if there are any updates on this or anything blocking the PR from being merged?

  • Maintainers were on separate pages about whether this should be enabled by default and what symbol should be used as prefix.
  • There are no automated tests for spaceship-prompt now. So, without extensive testing this may break some prompts and we don't want to introduce any breaking changes.

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}
Copy link
Member

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.

@slhck
Copy link

slhck commented May 4, 2018

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 and I don't think it should be enabled by default.

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.
@segevfiner
Copy link
Contributor Author

Rebased.

Copy link
Member

@salmanulfarzy salmanulfarzy left a 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

Status Image
Normal directory ✔️
Git repository ✔️
Subdirectoires inside Git repository ✔️
.git directory screenshot from 2018-05-04 21-25-53
Directory with space in name ✔️ screenshot from 2018-05-04 21-28-12
Git repository with spaces in name ✔️ screenshot from 2018-05-04 21-28-22
Symlinked directories ✔️ screenshot from 2018-05-04 21-30-50

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 salmanulfarzy merged commit d58d98c into spaceship-prompt:master Jul 10, 2018
@segevfiner segevfiner deleted the dir-trunc-prefix-3.0 branch July 11, 2018 17:39
@segevfiner
Copy link
Contributor Author

@salmanulfarzy #417 should fix the ".git directory" case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature A PR that implement feature (section, specific behavior, etc). proposal An issue (rarely PR) for feature-requests, ideas, etc
Development

Successfully merging this pull request may close these issues.

Issues with git module when path contains spaces
5 participants