Skip to content

Commit

Permalink
feat: Add keepassxc.openArgs config var for keepassxc-cli in open mode
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Aug 25, 2024
1 parent 61b4746 commit 82ebb6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ sections:
mode:
default: '`cache-password`'
description: See [KeePassXC functions](../templates/keepassxc-functions/index.md)
openArgs:
type: '[]string'
description: Extra args to KeePassXC CLI command, after `open` in open mode
prompt:
type: bool
default: '`true`'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ password prompt can be disabled by setting `keepassxc.prompt` to `false`.
By default, chezmoi will prompt for the KeePassXC password when required and
cache it for the duration of chezmoi's execution. Setting `keepassxc.mode` to
`open` will tell chezmoi to instead open KeePassXC's console with `keepassxc-cli
open`. chezmoi will use this console to request values from KeePassXC.
open` followed by `keepassxc.openArgs`. chezmoi will use this console to request
values from KeePassXC.
6 changes: 5 additions & 1 deletion internal/cmd/keepassxctemplatefuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type keepassxcConfig struct {
Database chezmoi.AbsPath `json:"database" mapstructure:"database" yaml:"database"`
Mode keepassxcMode `json:"mode" mapstructure:"mode" yaml:"mode"`
Args []string `json:"args" mapstructure:"args" yaml:"args"`
OpenArgs []string `json:"openArgs" mapstructure:"openArgs" yaml:"openArgs"`
Prompt bool `json:"prompt" mapstructure:"prompt" yaml:"prompt"`
cmd *exec.Cmd
console *expect.Console
Expand Down Expand Up @@ -198,7 +199,10 @@ func (c *Config) keepassxcOutputOpen(command string, args ...string) ([]byte, er
}

// Start the keepassxc-cli open command.
cmdArgs := append(slices.Clone(c.Keepassxc.Args), "open", c.Keepassxc.Database.String())
cmdArgs := slices.Clone(c.Keepassxc.Args)
cmdArgs = append(cmdArgs, "open")
cmdArgs = append(cmdArgs, c.Keepassxc.OpenArgs...)
cmdArgs = append(cmdArgs, c.Keepassxc.Database.String())
cmd := exec.Command(c.Keepassxc.Command, cmdArgs...) //nolint:gosec
env := os.Environ()
// Ensure prompt is in English.
Expand Down

0 comments on commit 82ebb6a

Please sign in to comment.