-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now, this only takes the first line of output from `pass`, which should be the same behavior as `pass -c`.
- Loading branch information
1 parent
3f93dda
commit 290d13e
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/twpayne/chezmoi/lib/chezmoi" | ||
vfs "github.com/twpayne/go-vfs" | ||
) | ||
|
||
var passCommand = &cobra.Command{ | ||
Use: "pass", | ||
Short: "Execute the pass CLI", | ||
RunE: makeRunE(config.runPassCommand), | ||
} | ||
|
||
// A PassCommandConfig is a configuration for the pass command. | ||
type PassCommandConfig struct { | ||
Pass string | ||
} | ||
|
||
var passCache = make(map[string]string) | ||
|
||
func init() { | ||
rootCommand.AddCommand(passCommand) | ||
config.Pass.Pass = "pass" | ||
config.addFunc("pass", config.passFunc) | ||
} | ||
|
||
func (c *Config) runPassCommand(fs vfs.FS, args []string) error { | ||
return c.exec(append([]string{c.Pass.Pass}, args...)) | ||
} | ||
|
||
func (c *Config) passFunc(id string) string { | ||
if s, ok := passCache[id]; ok { | ||
return s | ||
} | ||
name := c.Pass.Pass | ||
args := []string{id} | ||
if c.Verbose { | ||
fmt.Printf("%s %s\n", name, strings.Join(args, " ")) | ||
} | ||
output, err := exec.Command(name, args...).Output() | ||
if err != nil { | ||
chezmoi.ReturnTemplateFuncError(fmt.Errorf("pass: %s %s: %v", name, strings.Join(args, " "), err)) | ||
} | ||
password := strings.Split(string(output), "\n")[0] | ||
passCache[id] = password | ||
return passCache[id] | ||
} |