Display current checked out git branch name

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
jlahijani
Posts: 9
Joined: 23 Jan 2011 06:55

Display current checked out git branch name

Post by jlahijani »

Many developers customize their command line (bash, etc.) to show what git branch name they have checked out when they are in a folder that's under a git repository. Example:
https://coderwall.com/p/fasnya/add-git- ... ash-prompt

See the yellow "(develop)" part on the first line? That's the name of the branch and it's there as a label at the very end of the command prompt (ignore the other parts of this image):
Image

Is there a way to do the equivalent of this in XYplorer? When I go to a folder that's under a git repo, I'd like to know the branch name I have currently checked out (ideally somewhere at the top and distractingly visible). This is very important because depending on which git branch you have checked out, some files/folders may appear and some won't, which can be confusing if you forget about the fact that branches are in play and may affect what you're seeing.

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito »

Never thought about this, but now that you suggested it, I think that's a really neat idea! :tup:

I think the branch name should be displayed in the tab name.

EDIT: should this be moved to Wishes? I don't think this is something we can properly do with scripting.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Display current checked out git branch name

Post by highend »

I don't think this is something we can properly do with scripting.
Sure it can be done with scripting but it needs to be invoked manually...

Code: Select all

    $branch  = regexreplace(runret("git branch"), "\r?\n");
    $tabName = tab("get", "name");
    if (!$tabName) { $tabName = tab("get", "caption"); }
    $tabName = regexreplace($tabName, " \[\* .+?\]$");
    if (strpos($branch, "*") != -1) {
        $branch = regexreplace($branch, "^(?:\* )(.+?)(?=\r?\n|$)", "$1");
        tab("rename", "$tabName [* $branch]");
    } else {
        tab("rename", $tabName);
    }
1.png
1.png (1.56 KiB) Viewed 4230 times
2.png
2.png (1.87 KiB) Viewed 4230 times
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Display current checked out git branch name

Post by admin »

Can anybody explain this to a non-GITter? I have no idea what this is about. But if it's a simple thing I'm happy to add it...

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito »

highend wrote: 16 May 2019 15:18 it needs to be invoked manually...
My point exactly. For this to be actually enjoyable/beneficial, I don't see myself calling this script X times a day.

Plus once your tab is renamed, it stayed renamed, even if you browse to a different folder.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Display current checked out git branch name

Post by highend »

On each folder change invoke "git branch" and if there is an entry that begins with "*",
that's the name of the current branch. Add it to the tabs name like in the script
I've posted above...
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Display current checked out git branch name

Post by highend »

Plus once your tab is renamed, it stayed renamed, even if you browse to a different folder.
Ofc it does, I already said that it needs to be invoked manually...
One of my scripts helped you out? Please donate via Paypal

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito »

admin wrote: 16 May 2019 15:25 Can anybody explain this to a non-GITter? I have no idea what this is about.
https://www.atlassian.com/git/tutorials/using-branches

EDIT: this one is interesting as well without going into too much details: https://backlog.com/git-tutorial/using-branches/

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Display current checked out git branch name

Post by admin »

Thanks, but no time to read this ATM. So, let's put is this way: But is the wish here?

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito »

Basically, we use a git repository (a folder on our file system) that holds several branches. A branch represents a version of the files (and subfolders) in the repository. At a moment in time, we're always checked out to one branch (and only one). When we switch branches, it modifies the content of the folder (corresponding to the git repository). The wish here is to know to which branch (identified by its name: the default branches are usually named master, develop; or any other name you wish) we are currently checked out.

My proposal is to append it to the tab name.

Ideally, XYplorer should detect if the tab is listing the content of a git repository, and if so, get the branch name and display it automatically.

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Display current checked out git branch name

Post by admin »

Far out. A bit exotic maybe for a general purpose file manager?

Leito
Posts: 561
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito »

Maybe.

But you could add support to other VCS (SVN, Mercurial...) as well (Git is the most common, so first to do), and it would be a nice feature for developers.

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Display current checked out git branch name

Post by bdeshi »

Don, git is HUGE. Adding support for git status and metadata will be very attractive to a lot of potential customers!

the git executable's output structure is easily parseable by code; maybe you can just call git on location change to get necessary branch and repo status info. Git surely has some more accessible library too.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Display current checked out git branch name

Post by admin »

Thanks for the tip. Up to now I did not hear much from the GIT community. If that changes I will be happy to add this stuff. Looks easy enough...

xyuser123
Posts: 18
Joined: 06 Feb 2019 05:14

Re: Display current checked out git branch name

Post by xyuser123 »

I've never been a fan of adding integration with specific third party products. I think a more general solution would be an option to run a script on directory change, so that users who want this feature can use a script like the one highend posted.

Post Reply