Skip to content

Commit

Permalink
Add mozillaInstallHash template function
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Jul 1, 2021
1 parent e777b34 commit e872fa3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Manage your dotfiles securely across multiple machines.
* [`lastpass` *id*](#lastpass-id)
* [`lastpassRaw` *id*](#lastpassraw-id)
* [`lookPath` *file*](#lookpath-file)
* [`mozillaInstallHash` *path*](#mozillainstallhash-path)
* [`onepassword` *uuid* [*vault-uuid* [*account-name*]]](#onepassword-uuid-vault-uuid-account-name)
* [`onepasswordDocument` *uuid* [*vault-uuid* [*account-name*]]](#onepassworddocument-uuid-vault-uuid-account-name)
* [`onepasswordDetailsFields` *uuid* [*vault-uuid* [*account-name*]]](#onepassworddetailsfields-uuid-vault-uuid-account-name)
Expand Down Expand Up @@ -1729,6 +1730,11 @@ caution when using it in your templates.
{{ end }}
```

### `mozillaInstallHash` *path*

`mozillaInstallHash` returns the Mozilla install hash for *path*. This is a
convenience function to assist the management of Firefox profiles.

### `onepassword` *uuid* [*vault-uuid* [*account-name*]]

`onepassword` returns structured data from [1Password](https://1password.com/)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/repr v0.0.0-20201120212035-bb82daffcca2 // indirect
github.com/bmatcuk/doublestar/v4 v4.0.2
github.com/bradenhilton/mozillainstallhash v1.0.0
github.com/charmbracelet/glamour v0.3.0
github.com/coreos/go-semver v0.3.0
github.com/go-git/go-git/v5 v5.4.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ github.com/bketelsen/crypt v0.0.4 h1:w/jqZtC9YD4DS/Vp9GhWfWcCpuAL58oTnLoI8vE9YHU
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/bmatcuk/doublestar/v4 v4.0.2 h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA=
github.com/bmatcuk/doublestar/v4 v4.0.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bradenhilton/cityhash v1.0.0 h1:1QauDCwfxwIGwO2jBTJdEBqXgfCusAgQOSgdl4RsTMI=
github.com/bradenhilton/cityhash v1.0.0/go.mod h1:Wmb8yW1egA9ulrsRX4mxfYx5zq4nBWOCZ+j63oK6uz8=
github.com/bradenhilton/mozillainstallhash v1.0.0 h1:QL9byVGb4FrVOI7MubnME3uPNj5R78tqYQPlxuBmXMw=
github.com/bradenhilton/mozillainstallhash v1.0.0/go.mod h1:yVD0OX1izZHYl1lBm2UDojyE/k0xIqKJK78k+tdWV+k=
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func newConfig(options ...configOption) (*Config, error) {
"lastpass": c.lastpassTemplateFunc,
"lastpassRaw": c.lastpassRawTemplateFunc,
"lookPath": c.lookPathTemplateFunc,
"mozillaInstallHash": c.mozillaInstallHashTemplateFunc,
"onepassword": c.onepasswordTemplateFunc,
"onepasswordDetailsFields": c.onepasswordDetailsFieldsTemplateFunc,
"onepasswordDocument": c.onepasswordDocumentTemplateFunc,
Expand Down
10 changes: 10 additions & 0 deletions internal/cmd/templatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"runtime"

"github.com/bradenhilton/mozillainstallhash"
"howett.net/plist"

"github.com/twpayne/chezmoi/v2/internal/chezmoi"
Expand Down Expand Up @@ -79,6 +80,15 @@ func (c *Config) lookPathTemplateFunc(file string) string {
}
}

func (c *Config) mozillaInstallHashTemplateFunc(path string) string {
mozillaInstallHash, err := mozillainstallhash.MozillaInstallHash(path)
if err != nil {
returnTemplateError(err)
return ""
}
return mozillaInstallHash
}

func (c *Config) outputTemplateFunc(name string, args ...string) string {
output, err := c.baseSystem.IdempotentCmdOutput(exec.Command(name, args...))
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/testdata/scripts/templatefuncs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ stdout a${/}b
chezmoi execute-template '{{ lookPath "go" }}'
stdout go$exe

# test mozillaInstallHash template function
chezmoi execute-template '{{ mozillaInstallHash "/Applications/Firefox.app/Contents/MacOS" }}'
stdout 2656FF1E876E9973

# test stat template function
chezmoi execute-template '{{ (stat ".").isDir }}'
stdout true
Expand Down

0 comments on commit e872fa3

Please sign in to comment.