remove encrypted file handling for now
This commit is contained in:
parent
f7c2edc233
commit
5017580bee
|
|
@ -410,59 +410,10 @@ func NewNote(dir, title string, keywords []string, fileType, identifier string)
|
|||
return path, nil
|
||||
}
|
||||
|
||||
// NewNoteEncrypted creates a new encrypted denote note using CryptPut
|
||||
func NewNoteEncrypted(dir, title string, keywords []string, fileType, identifier string) (string, error) {
|
||||
if _, err := exec.LookPath("CryptPut"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "CryptPut is not installed.\ngit clone https://github.com/lneely/acme-crypt\n")
|
||||
return "", fmt.Errorf("CryptPut not available")
|
||||
}
|
||||
|
||||
// Use provided identifier or generate new one
|
||||
if identifier == "" {
|
||||
identifier = time.Now().Format("20060102T150405")
|
||||
}
|
||||
|
||||
// Format file name (without .gpg extension - CryptPut will add it)
|
||||
titleSlug := strings.ReplaceAll(strings.ToLower(title), " ", "-")
|
||||
titleSlug = regexp.MustCompile(`[^a-z0-9-]`).ReplaceAllString(titleSlug, "")
|
||||
|
||||
var keywordsPart string
|
||||
if len(keywords) > 0 {
|
||||
keywordsPart = "__" + strings.Join(keywords, "_")
|
||||
}
|
||||
|
||||
ext := fileExtensions[fileType]
|
||||
filename := fmt.Sprintf("%s--%s%s%s", identifier, titleSlug, keywordsPart, ext)
|
||||
plainPath := filepath.Join(dir, filename)
|
||||
|
||||
template := templates[fileType]
|
||||
dateStr := time.Now().Format("2006-01-02 Mon 15:04")
|
||||
keywordsStr := formatTags(keywords, fileType)
|
||||
content := fmt.Sprintf(template, title, dateStr, keywordsStr, identifier)
|
||||
|
||||
cmd := exec.Command("CryptPut", plainPath)
|
||||
cmd.Stdin = strings.NewReader(content)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return "", fmt.Errorf("failed to create encrypted file: %v", err)
|
||||
}
|
||||
encryptedPath := plainPath + ".gpg"
|
||||
|
||||
return encryptedPath, nil
|
||||
}
|
||||
|
||||
// Open opens a file using the appropriate method based on file extension
|
||||
// Open opens a file using plumb
|
||||
func Open(filePath string) error {
|
||||
if strings.HasSuffix(strings.ToLower(filePath), ".gpg") {
|
||||
if _, err := exec.LookPath("CryptGet"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "CryptGet is not installed.\ngit clone https://github.com/lneely/acme-crypt\n")
|
||||
return fmt.Errorf("CryptGet not available")
|
||||
}
|
||||
cmd := exec.Command("CryptGet", filePath)
|
||||
return cmd.Run()
|
||||
} else {
|
||||
cmd := exec.Command("plumb", filePath)
|
||||
return cmd.Run()
|
||||
}
|
||||
cmd := exec.Command("plumb", filePath)
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// IdentifierToPath converts a denote identifier to a file path
|
||||
|
|
|
|||
12
main.go
12
main.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
"strings"
|
||||
"unicode"
|
||||
|
||||
"9fans.net/go/acme"
|
||||
"9fans.net/go/plan9"
|
||||
"9fans.net/go/plan9/client"
|
||||
)
|
||||
|
|
@ -178,6 +179,9 @@ func main() {
|
|||
|
||||
ui.WindowDirty(newWin, true)
|
||||
ui.DotToAddr(newWin, "$")
|
||||
|
||||
// Start event listener for this note window
|
||||
go watchNoteWindow(newWin, fullPath)
|
||||
case "Remove":
|
||||
// Read chorded argument
|
||||
input := strings.TrimSpace(string(e.Arg))
|
||||
|
|
@ -422,3 +426,11 @@ func extractIdentifierFromFilename(filename string) string {
|
|||
}
|
||||
return matches[1]
|
||||
}
|
||||
|
||||
func watchNoteWindow(win *acme.Win, path string) {
|
||||
defer win.CloseFiles()
|
||||
|
||||
for e := range win.EventChan() {
|
||||
win.WriteEvent(e)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue