Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP - shorten directory relative to repo root#465

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
felixSchl wants to merge1 commit intoliquidprompt:master
base:master
Choose a base branch
Loading
fromfelixSchl:feature/vcs-reldir

Conversation

@felixSchl
Copy link
Contributor

@felixSchlfelixSchl commentedSep 6, 2016
edited
Loading

demo:https://asciinema.org/a/21be5t92ib26uddrs9ehuaovr

I reported this as a feature request early last year:#349.
I have since brushed up on my shell skills and feel comfortable delivering the said feature set.

What's left to do?

  • show relative path when ingit repo
  • show relative path when insvn repo
  • show relative path when inhg repo
  • show relative path when inbzr repo
  • show relative path when infossil repo
  • configure colouring of repo name (currently uses$LP_COLOR_PATH_ROOT) -input required
  • toggle feature ON/OFF via option -input required
  • how should this interact with the ordinary directory shortening? -input required

The way it's implemented itshould be easy to add support for the supported VCS systems, provided they have a way to get the top-level directory... otherwise we might half to walk the file system, but I hope not.

I'd say supporting submodules as mentioned in the original issue would be a separate PR, but I personally lost interest in that feature.

@felixSchlfelixSchlforce-pushed thefeature/vcs-reldir branch 3 times, most recently from03a8d80 tob9390a3CompareSeptember 7, 2016 17:56
@felixSchl
Copy link
ContributorAuthor

Alright, detecting the root is implemented for all supported VCSs (afaict). I've also had to fix up the awk script to run on OSX, but I could imagine it being broken elsewhere since the+ character was not escaped in the regex to mean literal+. I also took the liberty to span it across more lines to make it readable, but if you're precious of you sloc count, I can collapse them again.

@dolmen
Copy link
Collaborator

dolmen commentedSep 17, 2016
edited
Loading

I've cherry-picked your second commit ("Fix up awk script and make readable") as it was good and independent of the rest of this PR. Please rebase your branch on master and push -f.

@felixSchl
Copy link
ContributorAuthor

Alright, done.

Copy link
Collaborator

@dolmendolmen left a comment

Choose a reason for hiding this comment

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

This implementation (even with my remarks applied) will break thebash with LP_ENABLE_SHORTEN_PATH=0 and PROMPT_DIRTRIM set case.

liquidprompt Outdated
case"$LP_VCS_TYPE"in
git*) git rev-parse --show-toplevel; ;;
hg) hg root; ;;
svn) svn info| grep'Working Copy Root Path'| cut -d'' -f5-; ;;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add LANG=C

liquidprompt Outdated
# * Show the relative path from the root to "$PWD" in a different color
_lp_shorten_vcs_path () {
local root x
root="$(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move theroot assignment inside each case.

liquidprompt Outdated
)"||return
# trim leading and trailing whitespace, as well as a potentially trailing slash
root="${${${root##*[[:space:]]}%%[[:space:]]*}%/}"
if [!-z"$root" ];then
Copy link
Collaborator

Choose a reason for hiding this comment

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

if [[ -n "$root" ]]; then

liquidprompt Outdated
LP_MARK="$(_lp_sr"$(_lp_smart_mark$LP_VCS_TYPE)")"

_lp_shorten_path# set LP_PWD
_lp_shorten_vcs_path
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are calling bothlp_shorten_path and_lp_shorten_vcs_path. This is inefficient as only the result of one of them will matter.

  1. Instead of calling both,_lp_shorten_vcs_path should delegate to_lp_shorten_path in case it does not fillLP_PWD
  2. The call to_lp_shorten_vcs_path should be in aif [[ -n "$LP_VCS" ]] block

@felixSchl
Copy link
ContributorAuthor

felixSchl commentedSep 17, 2016
edited
Loading

This implementation (even with my remarks applied) will break the bash withLP_ENABLE_SHORTEN_PATH=0 andPROMPT_DIRTRIM set case.

From the comments above it seems you want to do either trimming or relative dirs? What do you think about combining the two, i.e. generalising the code to trim and then apply it as a last transform on whatever is present?

@dolmen
Copy link
Collaborator

This implementation (even with my remarks applied) will break the bash with LP_ENABLE_SHORTEN_PATH=0 and PROMPT_DIRTRIM set case.
From the comments above it seems you want to do either trimming or relative dirs?

No. I'm just telling the this particular user configuration has beenso optimised in liquidprompt that_lp_shorten_path is replaced by an implementation never update LP_PWD. If LP_PWD is changed by something else, nobody will restore it when exiting a VCS controlled directory.

One major concern is stability. I like your relative dirs idea (so once we have a good implementation I want it to be enabled by default), but I want existing users who upgrade to still be able to switch it off and go back to the previous behaviour.

What do you think about combining the two, i.e. generalising the code to trim and then apply it as a last transform on whatever is present?

This is interesting, but this is a much more tough project. It would require a more major rework of Liquidprompt and to be much more careful to not break things.

liquidprompt Outdated
# trim leading and trailing whitespace, as well as a potentially trailing slash
root="${${${root##*[[:space:]]}%%[[:space:]]*}%/}"
if [!-z"$root" ];then
if [-n"$root" ];then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use double brackets:[[ ... ]] instead of[ ... ]

@felixSchl
Copy link
ContributorAuthor

It would require a more major rework of Liquidprompt and to be much more careful to not break things.

What is holding me back a little is the lack of automated tests that I can run my changes through. Manually verifying is quite mundane for so many scenarios. I saw that many functions change global variables and are expected to be called in certain places under certain conditions. For example, I would have expected the shortening function to take as input the path to shorten and then return the new, shortened path, which would then be set at call site. I tried to make the added vcs shorten function to follow the existing pattern.

Would you accept a PR to set up CI with say travis?

@felixSchl
Copy link
ContributorAuthor

felixSchl commentedSep 17, 2016
edited
Loading

Btw, I am trying to reduce the number of added commits as we go along, but we can certainly squash later on once we're happy to remove meaningless commits like the one that just came in ("Use double-brackets") from the history.

@dolmen
Copy link
Collaborator

👍 for Travis. But we have no testsuite. The test.sh is very old and does not work with the current code. Open another issue to discuss that.

@dolmen
Copy link
Collaborator

Btw, I am trying to reduce the number of added commits as we go along, but we can certainly squash later on once we're happy to remove commits like the one that just came in ("Use double-brackets").

You can squash now if you want and push -f.

@Rycieos
Copy link
Collaborator

Release Candidate v2.0.0-rc.1 is now out, which means that the rework is complete. This has merge conflicts that need to be fixed.

Part of v2.0 was to support multiple path shortening methods and to highlight the VCS root and last directory. This gets close to what you were trying to do here, but none of the shortening methods show the path relative to the repo root (though all path formats will never shorten the repo root ifLP_PATH_VCS_ROOT is enabled). If you want to rebase and refactor to add a shortening method that would do that, I would be happy to merge such a feature.

Docs that would be helpful:
_lp_path_format()
LP_PATH_METHOD
LP_PATH_VCS_ROOT

And the_lp_path_format() source:
https://github.com/nojhan/liquidprompt/blob/2daf0e453039950d79dcf0eec5a04931e363a92a/liquidprompt#L861-L867

And feel free to ask for help!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dolmendolmendolmen requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@felixSchl@dolmen@Rycieos

[8]ページ先頭

©2009-2025 Movatter.jp