Skip to content

Commit

Permalink
Add support for nix-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaz committed Apr 23, 2018
1 parent 750abed commit c9640e9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var modules = map[string](func(*powerline)){
"user": segmentUser,
"venv": segmentVirtualEnv,
"vgo": segmentVirtualGo,
"nix-shell": segmentNixShell,
}

func comments(lines ...string) string {
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions segment-nix-shell.go
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
3 changes: 3 additions & 0 deletions themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ type Theme struct {
LoadHighBg uint8
LoadAvgValue byte
LoadThresholdBad float64

NixShellFg uint8
NixShellBg uint8
}
2 changes: 2 additions & 0 deletions themes/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"LoadHighBg": 161,
"LoadAvgValue": 5,
"LoadThresholdBad": 1.0,
"NixShellFg": 0,
"NixShellBg": 69,
"HostnameColorizedFgMap": {
"0": 250,
"1": 250,
Expand Down

0 comments on commit c9640e9

Please sign in to comment.