From c9640e9fb0e84ca7bb1e02eeb3d056e32384775c Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Mon, 23 Apr 2018 16:48:30 +0200 Subject: [PATCH] Add support for nix-shell --- README.md | 5 +++-- defaults.go | 6 ++++++ main.go | 7 ++++--- segment-nix-shell.go | 19 +++++++++++++++++++ themes.go | 3 +++ themes/default.json | 2 ++ 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 segment-nix-shell.go diff --git a/README.md b/README.md index 02b2a144..d93e94fd 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Ported to golang by @justjanne. - Changes color if the last command exited with a failure code - If you're too deep into a directory tree, shortens the displayed path with an ellipsis - Shows the current Python [virtualenv](http://www.virtualenv.org/) environment +- Shows if you are in a [nix](https://nixos.org.org/) shell - It's easy to customize and extend. See below for details. **Table of Contents** @@ -154,7 +155,7 @@ Usage of powerline-go: (default "patched") -modules string The list of modules to load, separated by ',' - (valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, load, perlbrew, perms, root, shell-var, ssh, time, user, venv, node) + (valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, load, nix-shell, perlbrew, perms, root, shell-var, ssh, time, user, venv, node) (default "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root") -newline Show the prompt on a new line @@ -167,7 +168,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, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, load, perlbrew, perms, root, ssh, time, user, venv, node) + (valid choices: aws, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, load, nix-shell, perlbrew, perms, root, ssh, time, user, venv, node) (default "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path") -shell string Set this to your shell type diff --git a/defaults.go b/defaults.go index 9521e1da..fcbe02d5 100644 --- a/defaults.go +++ b/defaults.go @@ -161,6 +161,9 @@ var themes = map[string]Theme{ LoadAvgValue: 5, LoadThresholdBad: 1.0, + NixShellFg: 00, + NixShellBg: 69, // a light blue + HostnameColorizedFgMap: map[uint8]uint8{ 0: 250, 1: 250, @@ -504,6 +507,9 @@ var themes = map[string]Theme{ LoadAvgValue: 5, LoadThresholdBad: 1.0, + NixShellFg: 69, // a light blue + NixShellBg: 254, + HostnameColorizedFgMap: map[uint8]uint8{ 0: 250, 1: 250, diff --git a/main.go b/main.go index 0bc663cf..7326bd5b 100644 --- a/main.go +++ b/main.go @@ -113,6 +113,7 @@ var modules = map[string](func(*powerline)){ "user": segmentUser, "venv": segmentVirtualEnv, "vgo": segmentVirtualGo, + "nix-shell": segmentNixShell, } func comments(lines ...string) string { @@ -167,14 +168,14 @@ func main() { "(valid choices: bare, bash, zsh)")), Modules: flag.String( "modules", - "venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root,vgo", + "nix-shell,venv,user,host,ssh,cwd,perms,git,hg,jobs,exit,root,vgo", commentsWithDefaults("The list of modules to load, separated by ','", - "(valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, load, perlbrew, perms, root, shell-var, ssh, termtitle, time, user, venv, vgo)")), + "(valid choices: aws, cwd, docker, dotenv, exit, git, gitlite, hg, host, jobs, load, nix-shell, perlbrew, perms, root, shell-var, ssh, termtitle, time, user, venv, vgo)")), Priority: flag.String( "priority", "root,cwd,user,host,ssh,perms,git-branch,git-status,hg,jobs,exit,cwd-path", commentsWithDefaults("Segments sorted by priority, if not enough space exists, the least priorized segments are removed first. Separate with ','", - "(valid choices: aws, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, load, perlbrew, perms, root, ssh, time, user, venv, vgo)")), + "(valid choices: aws, cwd, cwd-path, docker, exit, git-branch, git-status, hg, host, jobs, load, nix-shell, perlbrew, perms, root, ssh, time, user, venv, vgo)")), MaxWidthPercentage: flag.Int( "max-width", 0, diff --git a/segment-nix-shell.go b/segment-nix-shell.go new file mode 100644 index 00000000..858cf506 --- /dev/null +++ b/segment-nix-shell.go @@ -0,0 +1,19 @@ +package main + +import ( + "os" +) + +func segmentNixShell(p *powerline) { + var nixShell string + nixShell, _ = os.LookupEnv("IN_NIX_SHELL") + if nixShell == "" { + return + } else { + p.appendSegment("nix-shell", segment{ + content: nixShell, + foreground: p.theme.NixShellFg, + background: p.theme.NixShellBg, + }) + } +} diff --git a/themes.go b/themes.go index 4893846a..e45fd2f5 100644 --- a/themes.go +++ b/themes.go @@ -111,4 +111,7 @@ type Theme struct { LoadHighBg uint8 LoadAvgValue byte LoadThresholdBad float64 + + NixShellFg uint8 + NixShellBg uint8 } diff --git a/themes/default.json b/themes/default.json index 7bc01861..8fd326b2 100644 --- a/themes/default.json +++ b/themes/default.json @@ -61,6 +61,8 @@ "LoadHighBg": 161, "LoadAvgValue": 5, "LoadThresholdBad": 1.0, + "NixShellFg": 0, + "NixShellBg": 69, "HostnameColorizedFgMap": { "0": 250, "1": 250,