Skip to content

Commit

Permalink
config: add user variables
Browse files Browse the repository at this point in the history
  • Loading branch information
yields committed Aug 31, 2019
1 parent d1ed756 commit bf512ae
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bytes"
"io/ioutil"
"os/user"
"path"
"text/template"

Expand Down Expand Up @@ -76,6 +77,17 @@ func New(file string) (*Config, error) {
}
}

// Add the current user.
if _, ok := c.Variables["user"]; !ok {
if user, err := user.Current(); err == nil {
c.Variables["user"] = map[string]string{
"name": user.Name,
"username": user.Username,
"home": user.HomeDir,
}
}
}

// Interpolate variables.
if err := c.Eval(); err != nil {
return nil, err
Expand Down

0 comments on commit bf512ae

Please sign in to comment.