Add `note` command to store confidential texts / notes
leonklingele opened this issue · 7 comments
A new note
command would be helpful to store confidential texts / notes in addition to accounts
.
To add and edit a secure note:
$ pick note edit todo
Enter password:
..
Now, some kind of editor like vim is invoked.
Once this editor is closed, the note will be saved in pick.
To remove a secure note:
$ pick note rm todo
Enter password:
..
Note removed
This should be quite easy to implement using os/exec
which opens the default $EDITOR with a temporary file in ~/.pick/tmp
.
Once this file is closed, pick will copy the file's contents to memory, delete the file, and save the contents to the safe.
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
)
func main() {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vim"
}
editorPath, err := exec.LookPath(editor)
if err != nil {
log.Fatal(err)
}
tmpDir := os.TempDir() // "~/.pick/"
tmpFile, err := ioutil.TempFile(tmpDir, "pick.note.tmp")
if err != nil {
log.Fatal(err)
}
cmd := exec.Command(editorPath, tmpFile.Name())
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
if err := cmd.Wait(); err != nil {
log.Fatal("Done with error", err)
}
note, err := ioutil.ReadFile(tmpFile.Name())
if err != nil {
log.Fatal(err)
}
fmt.Println("Entered text:", string(note))
if err := os.Remove(tmpFile.Name()); err != nil {
log.Fatal(err)
}
}
Edit: Added os.Remove
to remove the tmp file.
Interesting idea.
I'd like to flush out the design for this feature before jumping into implementation (although I like the use of $EDITOR
). My concern is adding something that feels like a bolted on feature.
What if we add a --note
flag to the commands?
$ pick add --note foo
$ pick cat --note foo
$ pick ls --note
$ pick rm --note foo
Doesn't this make it much more complicated to implement and use?
I would rather add a $ pick note
subcommand
@leonklingele Thought about this last night, along with some other general design things, and am totally onboard with adding notes
as a first-class citizen.
Thanks for merging.