template / commit
Updated docs and removed all mentions of Dropbox. The default locations are now all directly under ~.
Makefile | 19 +++++++++++- README.md | 88 +++++++++++++++++++++++++++++++------------------------ default_config.go | 16 +++++----- main.go | 3 +- profile.go | 4 +-- 5 files changed, 79 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 28a2431..18deb69 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,11 @@ else endif .SHELLFLAGS := -Command - BINARY_NAME := template +profile = "" +name = "" + .PHONY: test build: @@ -16,6 +18,21 @@ build: install: build ./scripts/clean-install.ps1 +run: +ifeq ($(name), "") +ifeq ($(profile), "") + go run . +else + go run . --profile=$(profile) +endif +else +ifeq ($(profile), "") + go run . --name=$(name) +else + go run . --profile=$(profile) --name=$(name) +endif +endif + test: build New-Item -ItemType Directory -Force -Path ./test | out-null go test -v ./... -coverprofile="./test/coverage.out" diff --git a/README.md b/README.md index 5bb5de0..733b249 100644 --- a/README.md +++ b/README.md @@ -16,43 +16,47 @@ This is a hackathon project that I used to learn Go (golang). This is one of the profiles that comes with the tool. ```yaml -profiles: - - isdefault: false + - file: + templatepath: "" + template: |- + # {{.Year}}-{{.Month}}-{{.Day}} + + Today's notes + + ## Todo + + 1. Check email + 2. Check chat + 3. Check calendar + 4. Check yesterday's notes + 5. Have fun! + 6. ADD MORE ITEMS HERE + isdefault: false name: daily - description: Creates a MD file in c:\work\daily-notes folder in the format YYYY-MM-DD[-vX].md - path: ~/Dropbox/DailyNotes + description: Creates a MD file in ~/DailyNotes folder in the format YYYY-MM-DD[-vX].md + path: ~/DailyNotes type: file namepatterns: - - '{{$version := getVersion}}{{.Year}}-{{.Month}}-{{.Day}}{{if (gt $version 1)}}v{{$version}}{{end}}.md' + - '{{.Year}}-{{.Month}}-{{.Day}}.md' postscripts: - code . "{{.Path}}" scriptshell: pwsh os: "" - filetemplatepath: "" - filetemplate: |- - # {{.Year}}-{{.Month}}-{{.Day}} - - Today's notes - - ## Todo - - 1. [ ] Check email - 2. [ ] Check chat - 3. [ ] Check calendar - 4. [ ] Check yesterday's notes - 5. [ ] Have fun! + files: [] ``` Using the above configuration: ```pwsh > template daily Config loaded from 'C:\Users\fuzzy\.template.yaml' +args: &[daily] Profile: daily -Creating file 'C:\Users\fuzzy\Dropbox\DailyNotes\2022-09-26.md' from template string -Executing post script: pwsh -c code . "C:\Users\fuzzy\Dropbox\DailyNotes\2022-09-26.md" +extras file ~/.template-extras.yaml does not exist, extras not being used +Creating file 'C:\Users\fuzzy\DailyNotes\2022-10-23.md' from template string +Executing post script: pwsh -c code . "C:\Users\fuzzy\DailyNotes\2022-10-23.md" ``` -This will cause VSCode to open the `~\Dropbox\DailyNotes` folder as a workspace, and the newly-created file `2022-09-26.md` will be opened as well. +This will cause VSCode to open the `~\DailyNotes` folder as a workspace, and the newly-created file `2022-09-26.md` will be opened as well. ## Requirements @@ -64,33 +68,41 @@ The default profiles use [PowerShell Core](https://github.com/PowerShell/PowerSh ## Running in development -- `go run .` - uses default profile "note" to create a date-stamped MD file in current folder -- `go run . blog` OR `go run . --profile blog` OR `go run . -p blog` - creates a date-stamped MD file in ~/Dropbox/Blog, opens in VSCode -- `go run . daily topic` OR `go run . --profile daily --name topic` OR `go run . -p daily -n topic` - creates a templated date-stamped MD file with `topic` in its name in ~/Dropbox/DailyNotes, opens in VSCode +- `make run` - uses default profile "note" to create a date-stamped MD file in current folder +- `make -e project=blog run` - creates a date-stamped MD file in ~/Dropbox/Blog, opens in VSCode +- `make -e profile=blog name=topic run` - creates a templated date-stamped MD file with `topic` in its name in ~/Blog, opens in VSCode ## Installation -To install the `template` application and default templates, you have 2 options: - -1. `.\scripts\clean-install.ps1` -2. In VSCode, run the "Clean install" job - -Both operations do the same thing. +``` +make install +``` Note: the above installation will remove any local template/config changes you may have made. ### Running after installation - `template` - uses default profile "note" to create a date-stamped MD file in current folder -- `template blog` OR `template --profile blog` OR `template -p blog` - creates a date-stamped MD file in ~/Dropbox/Blog, opens in VSCode -- `template daily topic` OR `template --profile daily --name topic` OR `template -p daily -n topic` - creates a templated date-stamped MD file with `topic` in its name in ~/Dropbox/DailyNotes, opens in VSCode +- `template blog` OR `template --profile blog` OR `template -p blog` - creates a date-stamped MD file in ~/Blog, opens in VSCode +- `template daily topic` OR `template --profile daily --name topic` OR `template -p daily -n topic` - creates a templated date-stamped MD file with `topic` in its name in ~/DailyNotes, opens in VSCode + +### Creating symbolic links + +template currently refers to paths under `~`. This is to ensure that it works on all systems. + +But I personally keep files in Dropbox, so I usually create symbolic links from (for example) `~/Blog` -> `~/Dropbox/Blog`. Here are the Powershell commands that I use, maybe they will be helpful for you. :) + +```powershell +New-Item -ItemType Junction -Path "~\Blog\" -Target (Resolve-Path "~\Dropbox\Blog") +New-Item -ItemType Junction -Path "~\DailyNotes\" -Target (Resolve-Path "~\Dropbox\DailyNotes") +New-Item -ItemType Junction -Path "~\Notes\" -Target (Resolve-Path "~\Dropbox\Notes") +New-Item -ItemType Junction -Path "~\Therapy\" -Target (Resolve-Path "~\Dropbox\Therapy") +New-Item -ItemType Junction -Path "~\Work\" -Target (Resolve-Path "~\Dropbox\Work") +``` ### Dev loop -1. `go mod tidy` - installs dependencies -2. `go run . $profile $name` - runs profile `$profile` and uses `$name` to create a new file/folder -3. `go test` - runs tests -4. `go install` - installs template locally +TODO ## Support @@ -107,6 +119,7 @@ Here are the basic features of the CLI that I want to keep: 1. Cross-platform 2. CLI is implemented in Go 3. Fast (under 1s) basic operation of templating file and folder names + 1. Postscripts can take longer, as long as the "basic operations" finish quickly enough. ### KISS @@ -121,11 +134,10 @@ The CLI should also not be too opinionated. Aside from `go`, there are no other Here is the future feature list: 1. Support for passing in a list of template values for custom values in the template. Use might look like this: `template work form123 --id=456 --corpOffice=SEA`. The passed-in extra values will be placed somewhere inside the template. Some value keys will not be allowed, like "time". -2. (Feature creep) Support some kind of Markdown editor running on templated files. This is probably overkill for this project, may need to create a separate app for this. Go markdown links: [parsing MD](https://github.com/gomarkdown/markdown), [rendering parsed MD](https://github.com/jsternberg/markdownfmt/blob/master/markdown/main.go). ## Contributing -Contributions are welcome. +Contributions are welcome, but unsolicited PRs are not. If you want to add a particular feature, open an issue first and suggest it. We'll discuss the feature and if I agree that it should be added, you can open a PR. I don't want to waste my time or your time. ## Authors and acknowledgment diff --git a/default_config.go b/default_config.go index 698d955..22c9055 100644 --- a/default_config.go +++ b/default_config.go @@ -5,8 +5,8 @@ func defaultConfig() Config { Profiles: []Profile{ { Name: "daily", - Description: "Creates a MD file in ~/Dropbox/DailyNotes folder in the format YYYY-MM-DD[-vX].md", - Path: "~/Dropbox/DailyNotes", + Description: "Creates a MD file in ~/DailyNotes folder in the format YYYY-MM-DD[-vX].md", + Path: "~/DailyNotes", Type: FileType, NamePatterns: []ParameterizedText{"{{.Year}}-{{.Month}}-{{.Day}}.md"}, File: File{ @@ -30,9 +30,9 @@ Today's notes }, { Name: "note", - Description: "Creates a MD file in ~/Dropbox/Notes in the format YYYY-MM-DD[-ProjectName][-vVersion].md", + Description: "Creates a MD file in ~/Notes in the format YYYY-MM-DD[-ProjectName][-vVersion].md", OS: "All", - Path: "~/Dropbox/Notes", + Path: "~/Notes", IsDefault: true, Type: FileType, NamePatterns: []ParameterizedText{ @@ -49,9 +49,9 @@ Today's notes }, { Name: "blog", - Description: "Creates a MD file in the ~/Dropbox/Blog folder in the format YYYY-MM-DD[-ProjectName][-vVersion].md", + Description: "Creates a MD file in the ~/Blog folder in the format YYYY-MM-DD[-ProjectName][-vVersion].md", OS: "All", - Path: "~/Dropbox/Blog", + Path: "~/Blog", File: File{ TemplatePath: "~/.templates/blog-template.md", }, @@ -87,9 +87,9 @@ Today's notes // }, { Name: "therapy", - Description: "Creates a MD file in the ~/Dropbox/Therapy folder in the format YYYY-MM-DD[-vVersion].md", + Description: "Creates a MD file in the ~/Therapy folder in the format YYYY-MM-DD[-vVersion].md", OS: "All", - Path: "~/Dropbox/Therapy", + Path: "~/Therapy", File: File{ Template: `# {{.Year}}-{{.Month}}-{{.Day}} diff --git a/main.go b/main.go index 84a850c..855e894 100644 --- a/main.go +++ b/main.go @@ -85,8 +85,7 @@ func main() { // read args args := context.Args() - fmt.Println("args:", args) - // args.Get(0) + fmt.Println("Args:", args) // get profile name from args // if not set explicitly, use first arg, if present diff --git a/profile.go b/profile.go index 7d9d95a..7aa0b64 100644 --- a/profile.go +++ b/profile.go @@ -103,7 +103,7 @@ func processProfile(profile Profile, projectName string, extras map[string]strin path := getFullPath(profile.Path, usr) err = os.Chdir(path) if err != nil { - return fmt.Errorf("unable to change directory to %v: %v", path, err) + return fmt.Errorf("unable to change directory (1) to %v: %v", path, err) } cwd = path } @@ -148,7 +148,7 @@ func processProfile(profile Profile, projectName string, extras map[string]strin } err := os.Chdir(fullPath) if err != nil { - return fmt.Errorf("unable to change directory to %v: %v", fullPath, err) + return fmt.Errorf("unable to change directory (2) to %v: %v", fullPath, err) } // create files in the new folder