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

Truncate git branch name #755

Closed
SunMar opened this issue May 28, 2021 · 9 comments · Fixed by #761 or #818
Closed

Truncate git branch name #755

SunMar opened this issue May 28, 2021 · 9 comments · Fixed by #761 or #818
Labels
🚀 feat New feature

Comments

@SunMar
Copy link

SunMar commented May 28, 2021

Hi,

While I was setting up I ran into the problem that my git branch names are too long. They can sometimes be up to 50 characters long which takes up a lot of space. It would be nice if it's possible to set a maximum (f.ex. 20 or 30 characters) and truncate anything after that.

@JanDeDobbeleer JanDeDobbeleer added the 🚀 feat New feature label May 28, 2021
JanDeDobbeleer added a commit that referenced this issue May 29, 2021
JanDeDobbeleer added a commit that referenced this issue May 29, 2021
JanDeDobbeleer added a commit that referenced this issue May 29, 2021
@SunMar
Copy link
Author

SunMar commented Jun 23, 2021

Sorry, took a bit for me to add back the git segment in my prompt. Thank you very much to take the time to add this feature @JanDeDobbeleer!

Unfortunately the new branch_max_length doesn't seem to be working for me. Possibly I'm doing something wrong?

mkdir omp_test
cd omp_test/
git init
git config user.email test@ohmyposh.dev
git config user.name omp
git commit --allow-empty -m test
git branch some-very-long-branch-name-that-is-going-to-take-up-65-characters
git checkout some-very-long-branch-name-that-is-going-to-take-up-65-characters

image

My git segment is configured like this:

{
    "type": "git",
    "style": "powerline",
    "powerline_symbol": "\ue0b0",
    "foreground": "#d4e157",
    "background": "#546e7a",
    "properties": {
        "display_status": true,
        "branch_max_length": "25"
    }
}

Here is my full theme file:

{
    "$schema": "https:\/\/raw.githubusercontent.com\/JanDeDobbeleer\/oh-my-posh3\/main\/themes\/schema.json",
    "final_space": true,
    "blocks": [
        {
            "type": "prompt",
            "alignment": "left",
            "segments": [
                {
                    "type": "os",
                    "style": "diamond",
                    "foreground": "#26c6da",
                    "background": "#546e7a"
                },
                {
                    "type": "session",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#000000",
                    "background": "#4e9a06"
                },
                {
                    "type": "time",
                    "style": "diamond",
                    "background": "#d3d7cf",
                    "foreground": "#000000",
                    "properties": {
                        "prefix": " \uf017 "
                    }
                },
                {
                    "type": "path",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#e4e4e4",
                    "background": "#3465a4",
                    "properties": {
                        "prefix": " \uf07c ",
                        "home_icon": "~",
                        "style": "full"
                    }
                },
                {
                    "type": "git",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#d4e157",
                    "background": "#546e7a",
                    "properties": {
                        "display_status": true,
                        "branch_max_length": "25"
                    }
                },
                {
                    "type": "root",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#100e23",
                    "background": "#ffe9aa"
                },
                {
                    "type": "python",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#100e23",
                    "background": "#906cff",
                    "properties": {
                        "prefix": " \ue235 "
                    }
                },
                {
                    "type": "exit",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#d3d7cf",
                    "background": "#000000",
                    "properties": {
                        "always_enabled": true,
                        "display_exit_code": true,
                        "error_color": "#cc2222",
                        "color_background": true,
                        "success_icon": "\u2714"
                    }
                }
            ]
        }
    ]
}

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Jun 23, 2021

@SunMar I take it you upgraded oh-my-posh and restarted your terminal

ooh wait, it's an int so you need to change it to "branch_max_length": 25

@SunMar
Copy link
Author

SunMar commented Jun 23, 2021

@JanDeDobbeleer yes in the screenshot you can see that I'm on the latest version 3.166.0 from yesterday and indeed I did restart the terminal just to be sure. Oh My Posh doesn't use a background service like powerline can, does it? I assumed I don't have to kill anything or reboot, just restart the terminal session.

Oops, sorry about the int, not sure why I put it between quotes. But changing that doesn't seem to resolve the issue, I'm still seeing the whole branch name when I expected to only see a partial some-very-long-branch-nam.

image

My updated theme is:

{
    "type": "git",
    "style": "powerline",
    "powerline_symbol": "\ue0b0",
    "foreground": "#d4e157",
    "background": "#546e7a",
    "properties": {
        "display_status": true,
        "branch_max_length": 25
    }
}

And the full updated JSON:

{
    "$schema": "https:\/\/raw.githubusercontent.com\/JanDeDobbeleer\/oh-my-posh3\/main\/themes\/schema.json",
    "final_space": true,
    "blocks": [
        {
            "type": "prompt",
            "alignment": "left",
            "segments": [
                {
                    "type": "os",
                    "style": "diamond",
                    "foreground": "#26c6da",
                    "background": "#546e7a"
                },
                {
                    "type": "session",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#000000",
                    "background": "#4e9a06"
                },
                {
                    "type": "time",
                    "style": "diamond",
                    "background": "#d3d7cf",
                    "foreground": "#000000",
                    "properties": {
                        "prefix": " \uf017 "
                    }
                },
                {
                    "type": "path",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#e4e4e4",
                    "background": "#3465a4",
                    "properties": {
                        "prefix": " \uf07c ",
                        "home_icon": "~",
                        "style": "full"
                    }
                },
                {
                    "type": "git",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#d4e157",
                    "background": "#546e7a",
                    "properties": {
                        "display_status": true,
                        "branch_max_length": 25
                    }
                },
                {
                    "type": "root",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#100e23",
                    "background": "#ffe9aa"
                },
                {
                    "type": "python",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#100e23",
                    "background": "#906cff",
                    "properties": {
                        "prefix": " \ue235 "
                    }
                },
                {
                    "type": "exit",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b0",
                    "foreground": "#d3d7cf",
                    "background": "#000000",
                    "properties": {
                        "always_enabled": true,
                        "display_exit_code": true,
                        "error_color": "#cc2222",
                        "color_background": true,
                        "success_icon": "\u2714"
                    }
                }
            ]
        }
    ]
}

@SunMar
Copy link
Author

SunMar commented Jun 23, 2021

Just to be sure I double checked PowerShell as well using the same theme file (with the int fix), and there it's also not truncating:

image

@JanDeDobbeleer
Copy link
Owner

@SunMar allow me to validate this. Maybe I missed something obvious. Can you in the meantime ensure git is up-to-date as well?

@SunMar
Copy link
Author

SunMar commented Jun 23, 2021

@JanDeDobbeleer Thank for taking the time to check.

My WSL is running Ubuntu 21.04 and has git version 2.30.2 installed, which is the latest version available in the Ubuntu repositories.

In Windows my git version is the latest 2.32.0 and in PowerShell my posh-git version is the latest 1.0.0.

Let me know if there is any else I can help with.

@JanDeDobbeleer
Copy link
Owner

@SunMar fix incoming. Json parses as float. Standard "unit test succeeds, integration test fails" scenario.

JanDeDobbeleer added a commit that referenced this issue Jun 23, 2021
@SunMar
Copy link
Author

SunMar commented Jun 23, 2021

@JanDeDobbeleer it's working now, thank you very much !! 🥳

Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚀 feat New feature
Projects
None yet
2 participants