diff --git a/assets/chezmoi.io/docs/reference/templates/variables.md b/assets/chezmoi.io/docs/reference/templates/variables.md index 12621d5bdec..14c4b6dd13d 100644 --- a/assets/chezmoi.io/docs/reference/templates/variables.md +++ b/assets/chezmoi.io/docs/reference/templates/variables.md @@ -10,6 +10,7 @@ chezmoi provides the following automatically-populated variables: | `.chezmoi.configFile` | string | The path to the configuration file used by chezmoi | | `.chezmoi.executable` | string | The path to the `chezmoi` executable, if available | | `.chezmoi.fqdnHostname` | string | The fully-qualified domain name hostname of the machine chezmoi is running on | +| `.chezmoi.gid` | string | The primary group ID | | `.chezmoi.group` | string | The group of the user running chezmoi | | `.chezmoi.homeDir` | string | The home directory of the user running chezmoi | | `.chezmoi.hostname` | string | The hostname of the machine chezmoi is running on, up to the first `.` | @@ -18,6 +19,7 @@ chezmoi provides the following automatically-populated variables: | `.chezmoi.osRelease` | string | The information from `/etc/os-release`, Linux only, run `chezmoi data` to see its output | | `.chezmoi.sourceDir` | string | The source directory | | `.chezmoi.sourceFile` | string | The path of the template relative to the source directory | +| `.chezmoi.uid` | string | The user ID | | `.chezmoi.username` | string | The username of the user running chezmoi | | `.chezmoi.version.builtBy` | string | The program that built the `chezmoi` executable, if set | | `.chezmoi.version.commit` | string | The git commit at which the `chezmoi` executable was built, if set | diff --git a/pkg/cmd/config.go b/pkg/cmd/config.go index 1c2ec3d8c3c..8ca733d4e0e 100644 --- a/pkg/cmd/config.go +++ b/pkg/cmd/config.go @@ -902,8 +902,10 @@ func (c *Config) defaultTemplateData() map[string]interface{} { // determined. Unset variables will trigger template errors if used, // alerting the user to the problem and allowing them to find alternative // solutions. - var username, group string + var gid, group, uid, username string if currentUser, err := user.Current(); err == nil { + gid = currentUser.Gid + uid = currentUser.Uid username = currentUser.Username if runtime.GOOS != "windows" { if rawGroup, err := user.LookupGroupId(currentUser.Gid); err == nil { @@ -972,6 +974,7 @@ func (c *Config) defaultTemplateData() map[string]interface{} { "configFile": c.configFileAbsPath.String(), "executable": executable, "fqdnHostname": fqdnHostname, + "gid": gid, "group": group, "homeDir": c.homeDir, "hostname": hostname, @@ -979,6 +982,7 @@ func (c *Config) defaultTemplateData() map[string]interface{} { "os": runtime.GOOS, "osRelease": osRelease, "sourceDir": c.SourceDirAbsPath.String(), + "uid": uid, "username": username, "version": map[string]interface{}{ "builtBy": c.versionInfo.BuiltBy,