Skip to content

Commit

Permalink
feat: julia segment
Browse files Browse the repository at this point in the history
resolves #157
  • Loading branch information
JanDeDobbeleer committed Nov 15, 2020
1 parent ff0fe9c commit 9875de3
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 435 deletions.
28 changes: 28 additions & 0 deletions docs/docs/segment-julia.md
@@ -0,0 +1,28 @@
---
id: julia
title: Julia
sidebar_label: Julia
---

## What

Display the currently active julia version when a folder contains `.jl` files.

## Sample Configuration

```json
{
"type": "julia",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#4063D8",
"properties": {
"prefix": " \uE624 "
}
}
```

## Properties

- display_version: `boolean` - display the julia version - defaults to `true`
1 change: 1 addition & 0 deletions docs/sidebars.js
Expand Up @@ -22,6 +22,7 @@ module.exports = {
"exit",
"git",
"golang",
"julia",
"kubectl",
"node",
"os",
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Expand Up @@ -4,9 +4,14 @@ go 1.15

require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/repr v0.0.0-20201103221029-55c485bd663f // indirect
github.com/distatus/battery v0.10.1-0.20200722221337-7e1bf2bbb15c
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gookit/color v1.3.1
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shirou/gopsutil v2.20.9+incompatible
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.6.1
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Expand Up @@ -4,6 +4,12 @@ github.com/JanDeDobbeleer/color v1.3.1-0.20201014085303-5ffcdf66388a h1:0gU8YI1Z
github.com/JanDeDobbeleer/color v1.3.1-0.20201014085303-5ffcdf66388a/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=
github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
github.com/alecthomas/repr v0.0.0-20201103221029-55c485bd663f h1:jXPaiovuWmnCXfJ8UYiiLtI/LAJPnaZnoV+LfIDEJRc=
github.com/alecthomas/repr v0.0.0-20201103221029-55c485bd663f/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -15,17 +21,23 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v2.20.9+incompatible h1:msXs2frUV+O/JLva9EDLpuJ84PrFsdCTCQex8PUdtkQ=
github.com/shirou/gopsutil v2.20.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
Expand All @@ -34,7 +46,11 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 3 additions & 0 deletions segment.go
Expand Up @@ -73,6 +73,8 @@ const (
Terraform SegmentType = "terraform"
// Golang writes which go version is currently active
Golang SegmentType = "go"
// Julia writes which julia version is currently active
Julia SegmentType = "julia"
// Powerline writes it Powerline style
Powerline SegmentStyle = "powerline"
// Plain writes it without ornaments
Expand Down Expand Up @@ -132,6 +134,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error {
Dotnet: &dotnet{},
Terraform: &terraform{},
Golang: &golang{},
Julia: &julia{},
}
if writer, ok := functions[segment.Type]; ok {
props := &properties{
Expand Down
33 changes: 11 additions & 22 deletions segment_golang.go
@@ -1,35 +1,24 @@
package main

import "regexp"

type golang struct {
props *properties
env environmentInfo
golangVersion string
language *language
}

func (g *golang) string() string {
if g.props.getBool(DisplayVersion, true) {
return g.golangVersion
}
return ""
return g.language.string()
}

func (g *golang) init(props *properties, env environmentInfo) {
g.props = props
g.env = env
g.language = &language{
env: env,
props: props,
commands: []string{"go"},
versionParam: "version",
extensions: []string{"*.go"},
versionRegex: `go(?P<version>[0-9]+.[0-9]+.[0-9]+)`,
}
}

func (g *golang) enabled() bool {
if !g.env.hasFiles("*.go") {
return false
}
if !g.env.hasCommand("go") {
return false
}
versionInfo, _ := g.env.runCommand("go", "version")
r := regexp.MustCompile(`go(?P<version>[0-9]+.[0-9]+.[0-9]+)`)
values := groupDict(r, versionInfo)
g.golangVersion = values["version"]
return true
return g.language.enabled()
}
90 changes: 0 additions & 90 deletions segment_golang_test.go

This file was deleted.

24 changes: 24 additions & 0 deletions segment_julia.go
@@ -0,0 +1,24 @@
package main

type julia struct {
language *language
}

func (j *julia) string() string {
return j.language.string()
}

func (j *julia) init(props *properties, env environmentInfo) {
j.language = &language{
env: env,
props: props,
commands: []string{"julia"},
versionParam: "--version",
extensions: []string{"*.jl"},
versionRegex: `julia version (?P<version>[0-9]+.[0-9]+.[0-9]+)`,
}
}

func (j *julia) enabled() bool {
return j.language.enabled()
}
46 changes: 46 additions & 0 deletions segment_language.go
@@ -0,0 +1,46 @@
package main

import "regexp"

type language struct {
props *properties
env environmentInfo
extensions []string
commands []string
versionParam string
versionRegex string
version string
}

func (l *language) string() string {
if l.props.getBool(DisplayVersion, true) {
return l.version
}
return ""
}

func (l *language) enabled() bool {
for i, extension := range l.extensions {
if l.env.hasFiles(extension) {
break
}
if i == len(l.extensions)-1 {
return false
}
}
var executable string
for i, command := range l.commands {
if l.env.hasCommand(command) {
executable = command
break
}
if i == len(l.commands)-1 {
return false
}
}
versionInfo, _ := l.env.runCommand(executable, l.versionParam)
r := regexp.MustCompile(l.versionRegex)
values := groupDict(r, versionInfo)
l.version = values["version"]
return true
}

0 comments on commit 9875de3

Please sign in to comment.