Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
seanwash committed May 3, 2024
0 parents commit d0e4987
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://github.com/github/gitignore/blob/main/Go.gitignore

# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

.DS_Store
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Jn

Just a simple utility to create or open a daily note.

```
/Users/seanwashbot/journal
└── 2024
└── 05
└── 01.md
└── 02.md
└── 03.md
```

## Todo

- [ ] Note template
- [ ] Tests 😏
- [ ] Raycast script
- [ ] Command to store configs at ~/.jn
- Journal destination
- File extension
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/seanwash/jn

go 1.22.2
66 changes: 66 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"
"path"
"time"
)

func main() {
fileExtension := ".md"
today := time.Now()
entryName := fmt.Sprintf("%02d%s", today.Day(), fileExtension)
homePath := getHomeDir()
rootPath := path.Join(homePath, "journal")
folderPath := path.Join(rootPath, fmt.Sprintf("%d", today.Year()), fmt.Sprintf("%02d", today.Month()))
entryPath := path.Join(folderPath, entryName)
cmd := exec.Command("open", entryPath)
entryExists, _ := exists(entryPath)

if entryExists {
runCmd(cmd)
} else {
createEntry(folderPath, entryPath)
runCmd(cmd)
}
}

func createEntry(folderPath string, entryPath string) {
err := os.MkdirAll(folderPath, 0700)
if err != nil {
log.Fatal("Could not create new folder", err)
}

_, err = os.Create(entryPath)
if err != nil {
log.Fatal("Could not create new entry", err)
}
}

func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err != nil {
return false, err
}

return true, nil
}

func getHomeDir() string {
homePath, err := os.UserHomeDir()
if err != nil {
log.Fatal("Could not get user's home dir: ", err)
}

return homePath
}

func runCmd(cmd *exec.Cmd) {
err := cmd.Run()
if err != nil {
log.Fatal("Could not run cmd: ", err)
}
}

0 comments on commit d0e4987

Please sign in to comment.