From fccb345a5d2f829f3c97248aa9d3c2ba54affa97 Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Tue, 7 Dec 2021 16:23:02 -0500 Subject: [PATCH] powerline: add shlvl --- modules/cli/powerline.nix | 9 +++++-- modules/cli/shlvl.patch | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 modules/cli/shlvl.patch diff --git a/modules/cli/powerline.nix b/modules/cli/powerline.nix index 37ef5f5..0755f9d 100644 --- a/modules/cli/powerline.nix +++ b/modules/cli/powerline.nix @@ -22,7 +22,7 @@ in args = lib.mkOption { type = lib.types.listOf lib.types.str; default = [ - "-modules=\${remote:+'user,host,'}nix-shell,git,jobs,cwd" + "-modules=\${remote:+'user,host,'}nix-shell,shlvl,git,jobs,cwd" "-git-assume-unchanged-size 0" "-theme ${theme}" "-path-aliases '~/git=~/git'" @@ -38,7 +38,12 @@ in config = lib.mkIf cfg.enable { environment.systemPackages = [ - (pkgs.powerline-go.overrideAttrs (old: { patches = [ ./bold.patch ]; })) + (pkgs.powerline-go.overrideAttrs (old: { + patches = [ + ./bold.patch + ./shlvl.patch + ]; + })) ]; programs.bash.interactiveShellInit = '' diff --git a/modules/cli/shlvl.patch b/modules/cli/shlvl.patch new file mode 100644 index 0000000..0290e2b --- /dev/null +++ b/modules/cli/shlvl.patch @@ -0,0 +1,52 @@ +From 9fd668e356c3b89601109d6f1f53e5843af00af4 Mon Sep 17 00:00:00 2001 +From: Sean Buckley +Date: Tue, 7 Dec 2021 16:18:40 -0500 +Subject: [PATCH] add segment-shlvl + +--- + main.go | 1 + + segment-shlvl.go | 23 +++++++++++++++++++++++ + 2 files changed, 24 insertions(+) + create mode 100644 segment-shlvl.go + +diff --git a/main.go b/main.go +index 02f4a4a..2bd111e 100644 +--- a/main.go ++++ b/main.go +@@ -97,6 +97,7 @@ var modules = map[string]func(*powerline) []pwl.Segment{ + "root": segmentRoot, + "shell-var": segmentShellVar, + "shenv": segmentShEnv, ++ "shlvl": segmentShlvl, + "ssh": segmentSSH, + "termtitle": segmentTermTitle, + "terraform-workspace": segmentTerraformWorkspace, +diff --git a/segment-shlvl.go b/segment-shlvl.go +new file mode 100644 +index 0000000..d8bba7d +--- /dev/null ++++ b/segment-shlvl.go +@@ -0,0 +1,23 @@ ++package main ++ ++import ( ++ pwl "github.com/justjanne/powerline-go/powerline" ++ "os" ++ "strconv" ++) ++ ++func segmentShlvl(p *powerline) []pwl.Segment { ++ ++ level, _ := os.LookupEnv("SHLVL") ++ leveli, err := strconv.Atoi(level) ++ ++ if err != nil || leveli < 1 { ++ return []pwl.Segment{} ++ } ++ return []pwl.Segment{{ ++ Name: "shlvl", ++ Content: "\uE7A2 " + level, ++ Foreground: 231, ++ Background: 55, ++ }} ++}