-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(segments): add Distrobox segment
Introduce a new segment to display the active Distrobox container name.
- Loading branch information
1 parent
2ddb3b1
commit c8f484e
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package segments | ||
|
||
import "github.com/jandedobbeleer/oh-my-posh/src/properties" | ||
|
||
type Distrobox struct { | ||
base | ||
|
||
ContainerId string | ||
Icon string | ||
} | ||
|
||
const ( | ||
DistroboxIcon properties.Property = "icon" | ||
) | ||
|
||
func (d *Distrobox) Enabled() bool { | ||
d.ContainerId = d.env.Getenv("CONTAINER_ID") | ||
d.Icon = d.props.GetString(DistroboxIcon, "\uED95 ") | ||
|
||
return d.ContainerId != "" | ||
} | ||
|
||
func (d *Distrobox) Template() string { | ||
return " {{ .Icon }} {{ .ContainerId }} " | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package segments | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jandedobbeleer/oh-my-posh/src/properties" | ||
"github.com/jandedobbeleer/oh-my-posh/src/runtime/mock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDistrobox(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ContainerId string | ||
ExpectedEnabled bool | ||
ExpectedString string | ||
Template string | ||
}{ | ||
{ | ||
Case: "in distrobox container", | ||
ContainerId: "fedora-toolbox", | ||
ExpectedEnabled: true, | ||
ExpectedString: "fedora-toolbox", | ||
Template: "{{ .ContainerId }}", | ||
}, | ||
{ | ||
Case: "not in container", | ||
ContainerId: "", | ||
ExpectedEnabled: false, | ||
}, | ||
{ | ||
Case: "with icon template", | ||
ContainerId: "ubuntu-dev", | ||
ExpectedEnabled: true, | ||
ExpectedString: "\uED95 ubuntu-dev", | ||
Template: "{{ .Icon }} {{ .ContainerId }}", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
distrobox := &Distrobox{} | ||
env := new(mock.Environment) | ||
|
||
env.On("Getenv", "CONTAINER_ID").Return(tc.ContainerId) | ||
|
||
distrobox.Init(properties.Map{}, env) | ||
|
||
assert.Equal(t, tc.ExpectedEnabled, distrobox.Enabled(), tc.Case) | ||
if tc.ExpectedEnabled { | ||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, distrobox), tc.Case) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
id: distrobox | ||
title: Distrobox | ||
sidebar_label: Distrobox | ||
--- | ||
|
||
## What | ||
|
||
Displays the [Distrobox] container name when inside a Distrobox container environment. | ||
|
||
## Sample Configuration | ||
|
||
import Config from "@site/src/components/Config.js"; | ||
|
||
<Config | ||
data={{ | ||
type: "distrobox", | ||
style: "powerline", | ||
powerline_symbol: "\uE0B0", | ||
foreground: "#ffffff", | ||
background: "#f07b3c", | ||
template: "{{ .Icon }}{{ .ContainerId }}", | ||
properties: { | ||
icon: "\uED95 " | ||
} | ||
}} | ||
/> | ||
|
||
## Template ([info][templates]) | ||
|
||
:::note default template | ||
|
||
```template | ||
{{ .Icon }}{{ .ContainerId }} | ||
``` | ||
|
||
::: | ||
|
||
### Properties | ||
|
||
| Name | Type | Description | | ||
| -------------- | -------- | ---------------------------------------------------------- | | ||
| `icon` | `string` | the icon to display - defaults to `\uED95 ` | | ||
| `.ContainerId` | `string` | the name of the active distrobox container | | ||
|
||
[Distrobox]: https://github.com/89luca89/distrobox | ||
[templates]: /docs/configuration/templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters