penv

package module
v0.0.0-...-7a4c6d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2015 License: MIT Imports: 10 Imported by: 9

README

penv

penv permanently sets environment variables. It supports the following:

  • bash - entries are added to ~/.bashrc
  • fish - entries are added to ~/.config/fish/config.fish
  • windows - entries are added to the registry for the current user
  • osx - entries are added to a user launchctl script. You will have to restart programs to pick up the new environment. (ie restart your terminal)

Installation

penv is both a library and a command. To use the library in your own code see the documentation. To install the command run:

go get github.com/badgerodon/penv/...

Here's its usage:

penv <command>

Commands:
  set <name> <value>
    Permanently NAME to VALUE in the environment

  unset <name>
    Permanently unset NAME in the environment

  append <name> <value>
    Permanently append VALUE to NAME in the environment

Gotchas

Windows requires at least Go 1.3.

Different operating systems / shells aren't really compatible. I'm able to discern which environment variables I'm responsible for with shells (like bash) by using their config files, but I can't do that with Windows. All appends will get collapsed into sets, and unsets aren't just masking the value, they may actually remove it.

In other words this command works but it's dangerous. If you set your PATH don't be surprised when it clears all the previous values and you can't get them back.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendEnv

func AppendEnv(name, value string) error

AppendEnv permanently appends an environment variable

func RegisterDAO

func RegisterDAO(priority int, condition func() bool, dao DAO)

RegisterDAO registers a new data access object. DAOs are evaluted based on priority and the condition function

func Save

func Save(env *Environment) error

Save saves the environment

func SetEnv

func SetEnv(name, value string) error

SetEnv permanently sets an environment variable

func UnsetEnv

func UnsetEnv(name string) error

UnsetEnv permanently unsets an environment variable

Types

type BashDAO

type BashDAO struct{}

BashDAO is a data access object for bash

type DAO

type DAO interface {
	Load() (*Environment, error)
	Save(*Environment) error
}

DAO defines the interface for loading and saving a set of environment variables

type Environment

type Environment struct {
	Appenders []NameValue
	Setters   []NameValue
	Unsetters []NameValue
}

Environment is a collection of appenders, setters and unsetters

func Load

func Load() (*Environment, error)

Load loads the environment

type NameValue

type NameValue struct {
	Name  string
	Value string
}

NameValue is a name value pair

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL