From 029e00ff576156bf149a896cc4b88adecce6a949 Mon Sep 17 00:00:00 2001 From: Jerome Schneider Date: Fri, 27 Dec 2024 15:26:17 +0100 Subject: [PATCH] Add Pulumi stack support --- README.md | 10 +++++----- args.go | 6 +++--- defaults.go | 3 +++ main.go | 1 + segment-pulumi_stack.go | 32 ++++++++++++++++++++++++++++++++ themes.go | 3 +++ 6 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 segment-pulumi_stack.go diff --git a/README.md b/README.md index cd47e904..8077a20a 100644 --- a/README.md +++ b/README.md @@ -248,12 +248,12 @@ Usage of powerline-go: (default "patched") -modules string The list of modules to load, separated by ',' - (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) + (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs. (default "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root") -modules-right string The list of modules to load anchored to the right, for shells that support it, separated by ',' - (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl) + (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl) Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs. -newline Show the prompt on a new line @@ -266,7 +266,7 @@ Usage of powerline-go: Use '~' for your home dir. You may need to escape this character to avoid shell substitution. -priority string Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ',' - (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) + (valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl) (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path") -shell string Set this to your shell type @@ -437,7 +437,7 @@ end ## License > This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -> +> > This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -> +> > You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/args.go b/args.go index 1d5cc88f..e12b7cc9 100644 --- a/args.go +++ b/args.go @@ -127,19 +127,19 @@ var args = arguments{ "modules", strings.Join(defaults.Modules, ","), commentsWithDefaults("The list of modules to load, separated by ','", - "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)", + "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)", "Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs.")), ModulesRight: flag.String( "modules-right", strings.Join(defaults.ModulesRight, ","), comments("The list of modules to load anchored to the right, for shells that support it, separated by ','", - "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl)", + "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, wsl)", "Unrecognized modules will be invoked as 'powerline-go-MODULE' executable plugins and should output a (possibly empty) list of JSON objects that unmarshal to powerline-go's Segment structs.")), Priority: flag.String( "priority", strings.Join(defaults.Priority, ","), commentsWithDefaults("Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','", - "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)")), + "(valid choices: aws, bzr, cwd, direnv, docker, docker-context, dotenv, duration, exit, fossil, gcp, git, gitlite, goenv, hg, host, jobs, kube, load, newline, nix-shell, node, perlbrew, perms, plenv, pulumi-stack, rbenv, root, rvm, shell-var, shenv, ssh, svn, termtitle, terraform-workspace, time, user, venv, vgo, vi-mode, wsl)")), MaxWidthPercentage: flag.Int( "max-width", defaults.MaxWidthPercentage, diff --git a/defaults.go b/defaults.go index 83c91ad1..4e54ad46 100644 --- a/defaults.go +++ b/defaults.go @@ -250,6 +250,9 @@ var defaults = Config{ PlEnvFg: 00, PlEnvBg: 32, + PulumiStackFg: 00, // black + PulumiStackBg: 230, // yellow + TFWsFg: 15, // white TFWsBg: 26, // blue diff --git a/main.go b/main.go index c1b37868..045dbd74 100644 --- a/main.go +++ b/main.go @@ -95,6 +95,7 @@ var modules = map[string]func(*powerline) []pwl.Segment{ "perlbrew": segmentPerlbrew, "plenv": segmentPlEnv, "perms": segmentPerms, + "pulumi-stack": segmentPulumiStack, "rbenv": segmentRbenv, "root": segmentRoot, "rvm": segmentRvm, diff --git a/segment-pulumi_stack.go b/segment-pulumi_stack.go new file mode 100644 index 00000000..3234317d --- /dev/null +++ b/segment-pulumi_stack.go @@ -0,0 +1,32 @@ +package main + +import ( + "os" + "os/exec" + "strings" + + pwl "github.com/justjanne/powerline-go/powerline" +) + +const confFile = "./Pulumi.yaml" + +func segmentPulumiStack(p *powerline) []pwl.Segment { + stat, err := os.Stat(confFile) + if err != nil { + return []pwl.Segment{} + } + if stat.IsDir() { + return []pwl.Segment{} + } + command := exec.Command("pulumi", "stack", "--show-name") + stack, err := command.Output() + if err != nil { + return []pwl.Segment{} + } + return []pwl.Segment{{ + Name: "pulumi-stack", + Content: strings.TrimSuffix(string(stack), "\n"), + Foreground: p.theme.PulumiStackFg, + Background: p.theme.PulumiStackBg, + }} +} diff --git a/themes.go b/themes.go index f52c9891..08f4a16a 100644 --- a/themes.go +++ b/themes.go @@ -127,6 +127,9 @@ type Theme struct { PlEnvFg uint8 PlEnvBg uint8 + PulumiStackFg uint8 + PulumiStackBg uint8 + TFWsFg uint8 TFWsBg uint8