Skip to content

Commit

Permalink
Add showGitBranch method to EnvironmentIndicatorPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hlipnick committed Feb 7, 2024
1 parent f94f8fc commit e28af62
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/EnvironmentIndicatorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class EnvironmentIndicatorPlugin implements Plugin

public array|Closure|null $color = null;

public bool|Closure|null $showGitBranch = null;

public static function make(): static
{
$plugin = app(static::class);
Expand Down Expand Up @@ -83,6 +85,7 @@ public function register(Panel $panel): void
return View::make('filament-environment-indicator::badge', [
'color' => $this->getColor(),
'environment' => ucfirst(app()->environment()),
'branch' => $this->getGitBranch()
]);
});

Expand Down Expand Up @@ -131,6 +134,13 @@ public function showBorder(bool|Closure $showBorder = true): static
return $this;
}

public function showGitBranch(bool|Closure $showGitBranch = true): static
{
$this->showGitBranch = $showGitBranch;

return $this;
}

public function color(array|Closure $color = Color::Pink): static
{
$this->color = $color;
Expand All @@ -142,4 +152,16 @@ protected function getColor(): array
{
return $this->evaluate($this->color);
}

protected function getGitBranch(): ?string
{
if (! $this->evaluate($this->showGitBranch)) {
return null;
}
try {
return trim(exec('git branch --show-current'));
} catch (\Throwable $th) {
return null;
}
}
}

0 comments on commit e28af62

Please sign in to comment.