Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (34 sloc) 670 Bytes
package sshvault
import (
"io/ioutil"
"os"
"os/exec"
)
// Edit opens $EDITOR default to vi
func (v *vault) Edit(data []byte) ([]byte, error) {
tmpfile, err := ioutil.TempFile("", v.Fingerprint)
if err != nil {
return nil, err
}
defer Shred(tmpfile.Name())
err = ioutil.WriteFile(tmpfile.Name(), data, 0600)
if err != nil {
return nil, err
}
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vi"
}
cmd := exec.Command(editor, tmpfile.Name())
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
err = cmd.Run()
if err != nil {
return nil, err
}
b, err := ioutil.ReadFile(tmpfile.Name())
if err != nil {
return nil, err
}
return b, nil
}
You can’t perform that action at this time.