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

Extend git plugin to allow breaking path pre- and post- git repo root #96

Open
JanPokorny opened this issue May 22, 2019 · 4 comments
Open

Comments

@JanPokorny
Copy link

It would be cool if it was possible to display paths like fish does:

obrazek

Top is pshazz (theme agnoster-alternate), bottom is fish. The git root is in the iTerm2-Color-Schemes folder, and I am currently in the terminal subfolder. You can see that fish shows git info at git root, also treating path before/after repo root differently (in this case abbreviating the path before repo root just to single letters).

I believe this could be achieved by hardcoding git rev-parse --show-toplevel in the theme to get the repo root path (and determine the "rest" from full path), but a cleaner and faster solution would be to get direct support from the git plugin.

@chawyehsu
Copy link
Collaborator

Sounds good to me. I've added labels and see if anyone wants to implement it.

@JanPokorny
Copy link
Author

On another thought, the split would be better in three parts: path before, repo folder name, and path after. That way themes could easily theme the repo name differently (it has lighter color in my screenshot, for example).

@JanPokorny
Copy link
Author

@h404bi I was able to replicate the fish behavior:

obrazek

...using some really ugly code:

{
    "plugins": [ "git", "ssh", "z" ],
    "prompt": [
        [ "", "", "$($global:g=$git_branch.Length; If($global:g) { $global:path_git_root=((git rev-parse --show-toplevel) -replace '/','\\'); $path_real=($path -replace '^~',$home); $global:path_git_rest=($path_real -replace ('^'+[Regex]::Escape($global:path_git_root)),'') -replace '^\\\\',''; $global:path_git_root_split=($global:path_git_root -replace '\\\\([^\\\\]+)$','|$1').Split('|'); })"],
        [ "darkblue", "gray", " ${user}@${hostname}" ],
        [ "gray", "darkblue", "${rightarrow}" ],
        [ "white", "darkblue", " $( If($global:g) { ($global:path_git_root_split[0] -replace '\\\\([^\\\\])[^\\\\]+','\\$1') + '\\' + $global:path_git_root_split[1] } Else { $path } ) " ],
        [ "darkblue", "black", "$( If(!$global:g) { $rightarrow } )" ],
        [ "darkblue", "darkyellow", "$( If($global:g) { $rightarrow} )" ],
        [ "white", "darkyellow", "$(If($global:g) { ' ' + ([text.encoding]::utf8.getstring((238,130,160)) + ' ' + (($git_branch + ' ') -replace '^master $','') + $git_local_state + $git_remote_state).Trim() + ' ' })" ],
        [ "darkyellow", "black", "$(If($global:g -and !$global:path_git_rest.Length) { $rightarrow })" ],
        [ "darkyellow", "darkblue", "$(If($global:g -and $global:path_git_rest.Length) { $rightarrow })" ],
        [ "white", "darkblue", "$(If($global:g -and $global:path_git_rest.Length) { ' ' + $global:path_git_rest + ' ' })" ],
        [ "darkblue", "black", "$(If($global:g -and $global:path_git_rest.Length) { $rightarrow })" ],
        [ "", "", " `n`" ]
    ],
    "git": {
        "prompt_unstaged": "*",
        "prompt_staged": "~",
        "prompt_stash": "$",
        "prompt_untracked": "",
        "prompt_remote_push": "+",
        "prompt_remote_pull": "-",
        "prompt_remote_same": " "
    }
}

@JanPokorny
Copy link
Author

@h404bi @lukesampson What are your thoughts on this approach? Does it deserve support in the Git plugin? Three variables are needed: path before current repo root, repo root folder name, rest of path after repo root folder. It seems functional so far and mimics the bobthefish behavior quite well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants