t

commit ea6daf25c2a4789beba5cbd69a3f43dbfb8c2895

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

First iteration, basic file creation and calling an editor

File creation based on time and for now, we're just calling vim

 README.md | 34 +++++++++++++++++++++
 src/main.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++


diff --git a/README.md b/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..7da701e107f1b43c2d7a1ec78a3517194ea01449
--- /dev/null
+++ b/README.md
@@ -0,0 +1,34 @@
+# t
+
+
+`t` is an minimalistic tool to take notes.
+
+## Philosophy
+
+Instead of using a web editor or something like an web editor, or an
+fully bloated app to take your notes and store them on someone's server
+with their proprietary software and APIs we choose to use something way
+more simple, a combination of bunch of very well documented and trusted
+tools, *git* and *markdown*.
+
+## Design
+
+`t` is designed to be completely simple and out of your way. Especially
+when taking notes, sometimes all you want is somewhere to drop a bunch
+of thoughts.
+
+When writing a note, `t` will open your `EDITOR` (we recommend vim). As
+soon that you write all you need and quit the app, `t` will push your
+note to the configured git server. That's it.
+
+## Contributing
+
+Send me an email at
+[pedrolucasporcellis@gmail.com](mailto:pedrolucasporcellis@gmail.com)
+
+## License
+
+MIT License
+
+
+




diff --git a/src/main b/src/main
new file mode 100755
index 0000000000000000000000000000000000000000..95344740f802ad28d425bd6e87fe56a9419ad8fd
Binary files /dev/null and b/src/main differ




diff --git a/src/main.go b/src/main.go
new file mode 100644
index 0000000000000000000000000000000000000000..5da59ce5f393362b18de462f7753d5440d02b4f6
--- /dev/null
+++ b/src/main.go
@@ -0,0 +1,86 @@
+package main
+
+import (
+  "fmt"
+  "os"
+  "io/ioutil"
+  "os/exec"
+  "time"
+)
+
+func generateNoteFileTitle() string {
+  currentTime := time.Now()
+
+  return currentTime.Format("2006-01-02T15:04:05Z07:00")
+}
+
+func createNoteFile() (string, error) {
+  file, err := os.Create(fmt.Sprintf("%s%s.md", notesDirectory(), generateNoteFileTitle()))
+
+  if err != nil {
+    fmt.Println("Could not create the file")
+    fmt.Println(err)
+  }
+
+  fileName := file.Name()
+  file.Close()
+
+  return fileName, err
+}
+
+func executeEditor(fileName string) error {
+  cmd := exec.Command("vim", fileName)
+  cmd.Stdin  = os.Stdin
+  cmd.Stdout = os.Stdout
+  cmd.Stderr = os.Stderr
+
+  return cmd.Run()
+}
+
+func captureText() ([]byte, error) {
+  var err error
+  var fileName string 
+
+  fileName, creationErr := createNoteFile()
+  
+  if creationErr != nil {
+    return []byte{}, creationErr
+  }
+
+  if err = executeEditor(fileName); err != nil {
+    return []byte{}, err
+  }
+  
+  bytes, err := ioutil.ReadFile(fileName)
+
+  if err != nil {
+    return []byte{}, err
+  }
+
+  fmt.Println(bytes)
+
+  return bytes, nil
+}
+
+func notesDirectory() string {
+  homeDir := os.Getenv("HOME")
+
+  if homeDir == "" {
+    fmt.Println("ERROR: You must have set your $HOME directory")
+  }
+
+  notesDirectory := fmt.Sprintf("%s/notes/", homeDir)
+
+  return notesDirectory
+}
+
+func main() {
+  fmt.Println("Starting...")
+  
+  data, err := captureText()
+
+  fmt.Println(data)
+  fmt.Println(err)
+
+  fmt.Println("Finished...")
+}