Skip to content

Commit

Permalink
Add --bitwarden-session flag
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Dec 22, 2018
1 parent cbd9256 commit 5301881
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ Unlock your Bitwarden vault:

$ bw unlock

Set the `BW_SESSION` environment variable, as instructed.
Set the `BW_SESSION` environment variable, as instructed. You can also pass the
session directly to `chezmoi` using the `--bitwarden-session` flag.

The structured data from `bw get` is available as the `bitwarden` template
function in your config files, for example:
Expand Down
13 changes: 12 additions & 1 deletion cmd/bitwarden.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@ var bitwardenCommand = &cobra.Command{
}

type bitwardenCommandConfig struct {
BW string
BW string
Session string
}

var bitwardenCache = make(map[string]interface{})

func init() {
rootCommand.AddCommand(bitwardenCommand)

persistentFlags := rootCommand.PersistentFlags()
persistentFlags.StringVar(&config.Bitwarden.Session, "bitwarden-session", "", "bitwarden session")

config.Bitwarden.BW = "bw"
config.addFunc("bitwarden", config.bitwardenFunc)
}

func (c *Config) runBitwardenCommand(fs vfs.FS, cmd *cobra.Command, args []string) error {
if c.Bitwarden.Session != "" {
args = append([]string{"--session", c.Bitwarden.Session}, args...)
}
return c.exec(append([]string{c.Bitwarden.BW}, args...))
}

Expand All @@ -39,6 +47,9 @@ func (c *Config) bitwardenFunc(args ...string) interface{} {
return data
}
name := c.Bitwarden.BW
if c.Bitwarden.Session != "" {
args = append([]string{"--session", c.Bitwarden.Session}, args...)
}
args = append([]string{"get"}, args...)
if c.Verbose {
fmt.Printf("%s %s\n", name, strings.Join(args, " "))
Expand Down

0 comments on commit 5301881

Please sign in to comment.