Skip to content

Commit

Permalink
Added segment for rbenv to display the current ruby version
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiandeutsch committed Aug 3, 2020
1 parent 59fef95 commit 50075d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var modules = map[string]func(*powerline) []pwl.Segment{
"perlbrew": segmentPerlbrew,
"plenv": segmentPlEnv,
"perms": segmentPerms,
"rbenv": segmentRbenv,
"root": segmentRoot,
"shell-var": segmentShellVar,
"shenv": segmentShEnv,
Expand Down
31 changes: 31 additions & 0 deletions segment-rbenv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
pwl "github.com/justjanne/powerline-go/powerline"
"os/exec"
"strings"
)

func runRbenvCommand(cmd string, args ...string) (string, error) {
command := exec.Command(cmd, args...)
out, err := command.Output()
return string(out), err
}

func segmentRbenv(p *powerline) []pwl.Segment {
out, err := runRbenvCommand("rbenv", "version")

if err == nil {
items := strings.Split(out, " ")
if len(items) > 1 {
return []pwl.Segment{{
Name: "rbenv",
Content: items[0],
Foreground: p.theme.TimeFg,
Background: p.theme.TimeBg,
}}
}
}

return []pwl.Segment{}
}

0 comments on commit 50075d9

Please sign in to comment.