Display current checked out git branch name

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

Display current checked out git branch name

Post by jlahijani » 16 May 2019 03:51

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: 533
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito » 16 May 2019 14:05

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: 8209
Joined: 06 Feb 2011 00:33

Re: Display current checked out git branch name

Post by highend » 16 May 2019 15:18

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 322 times
2.png
2.png (1.87 KiB) Viewed 322 times
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

admin
Site Admin
Posts: 47182
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Display current checked out git branch name

Post by admin » 16 May 2019 15:25

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: 533
Joined: 26 Sep 2016 15:37
Location: Windows 10 1809 x64

Re: Display current checked out git branch name

Post by Leito » 16 May 2019 15:26

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: 8209
Joined: 06 Feb 2011 00:33

Re: Display current checked out git branch name

Post by highend » 16 May 2019 15:27

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 or highend (at) web (dot) de

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

Re: Display current checked out git branch name

Post by highend » 16 May 2019 15:27

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 or highend (at) web (dot) de

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

Re: Display current checked out git branch name

Post by Leito » 16 May 2019 15:34

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: 47182
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Display current checked out git branch name

Post by admin » 16 May 2019 15:52

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

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

Re: Display current checked out git branch name

Post by Leito » 16 May 2019 16:08

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: 47182
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Display current checked out git branch name

Post by admin » 16 May 2019 16:21

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

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

Re: Display current checked out git branch name

Post by Leito » 16 May 2019 16:33

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.

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

Re: Display current checked out git branch name

Post by SammaySarkar » 19 May 2019 12:43

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.

admin
Site Admin
Posts: 47182
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Display current checked out git branch name

Post by admin » 19 May 2019 13:09

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: 17
Joined: 06 Feb 2019 05:14

Re: Display current checked out git branch name

Post by xyuser123 » 19 May 2019 20:07

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