A button only visible in a git repository

With the help from ChatGPT, I've managed to create a custom MS-DOS command

for /f "tokens=*" %%a in ('git  -C {sourcepath} remote get-url origin') do set url=%%a
start "" "%url%"

If the current folder is a git repository, when I run the command by clicking a button, the remote URL will be opened in my default browser. Awesome.

However, I don't want the button always available.

I find DO has @ifexists, @hideif, and sort of thing, but I don't know how to group these functions together.

Can anyone shed some light?

A single line with @hideifpath should be enough.

@hideifpath:....not git repo....
open_remote

What do I fill in ....not git repo....?

The path definition(s) for your repositories, prefixed with ! to invert the logic.

This implementation will not be portable.

A folder is considered as a git repo when

  • "./.git" exists, or "../.git", "../../.git", "../../../.git", etc. exist.
  • or "git -C {sourcepath} remote get-url origin" doesn't return error.

Try

@hideifpath:!*\.git
  • or "git -C {sourcepath} remote get-url origin" doesn't return error.

That's impossible to test for this purpose.

It looks promising but needs a little tweaks at best.

Your code makes the button visible when the current path ends with ".git", which is incorrect.
dopus_rQ2K69w1lv

The button needs to be visible when the current path + "./git" exists, as the following figure shows.

dopus_5uk54gEHLL

The basic requirement is that assume the current folder is "C:/a/b/c", the button should be visible if "C:/a/b/c/.git" exists.

The bonus requirement is that assume the current folder is "C:/a/b/c", the button should be visible if any of "C:/a/b/.git", "C:/a/.git", "C:/.git" exists.

I see... Sorry, I think we can only examine the current path, not check for any subfolders. The next version might support this, I remember reading about plans to enhance the modifier system.

Thank you for the help anyway. I can't wait to see the new feature.