mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 20:27:28 -08:00
parent
39594b0d34
commit
2751a243ef
|
@ -126,6 +126,8 @@ const (
|
|||
DENO SegmentType = "deno"
|
||||
// DOTNET writes which dotnet version is currently active
|
||||
DOTNET SegmentType = "dotnet"
|
||||
// ELIXIR writes the elixir version
|
||||
ELIXIR SegmentType = "elixir"
|
||||
// EXECUTIONTIME writes the execution time of the last run command
|
||||
EXECUTIONTIME SegmentType = "executiontime"
|
||||
// EXIT writes the last exit code
|
||||
|
@ -246,6 +248,7 @@ var Segments = map[SegmentType]func() SegmentWriter{
|
|||
DENO: func() SegmentWriter { return &segments.Deno{} },
|
||||
DOTNET: func() SegmentWriter { return &segments.Dotnet{} },
|
||||
EXECUTIONTIME: func() SegmentWriter { return &segments.Executiontime{} },
|
||||
ELIXIR: func() SegmentWriter { return &segments.Elixir{} },
|
||||
EXIT: func() SegmentWriter { return &segments.Exit{} },
|
||||
FLUTTER: func() SegmentWriter { return &segments.Flutter{} },
|
||||
FOSSIL: func() SegmentWriter { return &segments.Fossil{} },
|
||||
|
|
34
src/segments/elixir.go
Normal file
34
src/segments/elixir.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package segments
|
||||
|
||||
import (
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/properties"
|
||||
)
|
||||
|
||||
type Elixir struct {
|
||||
language
|
||||
}
|
||||
|
||||
func (e *Elixir) Template() string {
|
||||
return languageTemplate
|
||||
}
|
||||
|
||||
func (e *Elixir) Init(props properties.Properties, env platform.Environment) {
|
||||
e.language = language{
|
||||
env: env,
|
||||
props: props,
|
||||
extensions: []string{"*.ex"},
|
||||
commands: []*cmd{
|
||||
{
|
||||
executable: "elixir",
|
||||
args: []string{"--version"},
|
||||
regex: `Elixir (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
||||
},
|
||||
},
|
||||
versionURLTemplate: "https://github.com/elixir-lang/elixir/releases/tag/v{{ .Full }}",
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Elixir) Enabled() bool {
|
||||
return e.language.Enabled()
|
||||
}
|
35
src/segments/elixir_test.go
Normal file
35
src/segments/elixir_test.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package segments
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestElixir(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
}{
|
||||
{
|
||||
Case: "elixir 1.14.2",
|
||||
ExpectedString: "1.14.2",
|
||||
Version: "Erlang/OTP 25 [erts-13.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]\n\nElixir 1.14.2 (compiled with Erlang/OTP 25)",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
params := &mockedLanguageParams{
|
||||
cmd: "elixir",
|
||||
versionParam: "--version",
|
||||
versionOutput: tc.Version,
|
||||
extension: "*.ex",
|
||||
}
|
||||
env, props := getMockedLanguageEnv(params)
|
||||
r := &Elixir{}
|
||||
r.Init(props, env)
|
||||
assert.True(t, r.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, r.Template(), r), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
|
@ -2028,6 +2028,37 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "elixir"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"title": "Elixir Segment",
|
||||
"description": "https://ohmyposh.dev/docs/segments/elixir",
|
||||
"properties": {
|
||||
"properties": {
|
||||
"properties": {
|
||||
"home_enabled": {
|
||||
"$ref": "#/definitions/home_enabled"
|
||||
},
|
||||
"fetch_version": {
|
||||
"$ref": "#/definitions/fetch_version"
|
||||
},
|
||||
"display_mode": {
|
||||
"$ref": "#/definitions/display_mode"
|
||||
},
|
||||
"missing_command_text": {
|
||||
"$ref": "#/definitions/missing_command_text"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
|
|
55
website/docs/segments/elixir.mdx
Normal file
55
website/docs/segments/elixir.mdx
Normal file
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
id: elixir
|
||||
title: Elixir
|
||||
sidebar_label: Elixir
|
||||
---
|
||||
|
||||
## What
|
||||
|
||||
Display the currently active elixir version.
|
||||
|
||||
## Sample Configuration
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "elixir",
|
||||
"style": "powerline",
|
||||
"powerline_symbol": "\uE0B0",
|
||||
"foreground": "#ffffff",
|
||||
"background": "#422251",
|
||||
"template": " \ue62d {{ .Full }} "
|
||||
}
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
| ---------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `home_enabled` | `boolean` | display the segment in the HOME folder or not - defaults to `false` |
|
||||
| `fetch_version` | `boolean` | fetch the flutter version - defaults to `true` |
|
||||
| `missing_command_text` | `string` | text to display when the command is missing - defaults to empty |
|
||||
| `display_mode` | `string` | <ul><li>`always`: the segment is always displayed</li><li>`files`: the segment is only displayed when `*.ex` files are present (**default**)</li></ul> |
|
||||
| `version_url_template` | `string` | a go [text/template][go-text-template] [template][templates] that creates the URL of the version info / release notes |
|
||||
|
||||
## Template ([info][templates])
|
||||
|
||||
:::note default template
|
||||
|
||||
```template
|
||||
{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | -------- | -------------------------------------------------- |
|
||||
| `.Full` | `string` | the full version |
|
||||
| `.Major` | `string` | major number |
|
||||
| `.Minor` | `string` | minor number |
|
||||
| `.URL` | `string` | URL of the version info / release notes |
|
||||
| `.Error` | `string` | error encountered when fetching the version string |
|
||||
|
||||
[go-text-template]: https://golang.org/pkg/text/template/
|
||||
[templates]: /docs/configuration/templates
|
|
@ -67,6 +67,7 @@ module.exports = {
|
|||
"segments/dart",
|
||||
"segments/deno",
|
||||
"segments/dotnet",
|
||||
"segments/elixir",
|
||||
"segments/executiontime",
|
||||
"segments/exit",
|
||||
"segments/flutter",
|
||||
|
|
Loading…
Reference in a new issue