template / commit
Start using `.ProjectName | snakecase` in daily profile and document this usage, as well as sprig.
README.md | 18 +++++++++++------- default_config.go | 16 +++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 143d8a8..5be8c33 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,14 @@ This is one of the profiles that comes with the tool. - name: daily description: Creates a MD file in ~/DailyNotes folder in the format YYYY-MM-DD[-vX].md isdefault: false + isdisabled: false type: file path: ~/DailyNotes namepatterns: - - '{{.Year}}-{{.Month}}-{{.Day}}.md' + - '{{$version := getVersion}}{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName | snakecase }}{{end}}{{if (gt $version 1)}}v{{$version}}{{end}}.md' runpostscriptonfailure: true postscripts: - - code . {{ if .FullPath }}"{{.FullPath}}"{{else}}(gci . | select -last 1){{ end }} + - code . {{ if .FullPath }}"{{.FullPath}}"{{else}}(ls -t | head -n1){{ end }} file: template: |- # {{.FileNameWithoutExtension}} @@ -48,17 +49,20 @@ This is one of the profiles that comes with the tool. Using the above configuration: ```sh -> template daily +> $ template daily "Cool Thought" Profile: daily -Project name: +Project name: Cool Thought Loaded config from /Users/fuzzy/.template.yaml Loaded user config from /Users/fuzzy/.template.user.yaml, combining with global config -Creating file: /Users/fuzzy/DailyNotes/2022-11-07.md -Executing post script: sh -c code . "/Users/fuzzy/DailyNotes/2022-11-07.md" +Creating file: /Users/fuzzy/DailyNotes/2022-11-20-cool_thought.md +Executing post script: sh -c code . "/Users/fuzzy/DailyNotes/2022-11-20-cool_thought.md" Post script had no output ``` -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. +This will cause VSCode to open the `~\DailyNotes` folder as a workspace, and the newly-created file `2022-11-20-cool_thought.md` will be opened as well. + +The above example also uses the [`snakecase`](https://github.com/Masterminds/sprig/blob/master/docs/strings.md#user-content-snakecase) template function. +This is one of the [sprig template functions](https://github.com/Masterminds/sprig/blob/master/docs/index.md) that are exposed by template. ## Requirements diff --git a/default_config.go b/default_config.go index a1f205b..c93437f 100644 --- a/default_config.go +++ b/default_config.go @@ -4,11 +4,17 @@ func defaultConfig() Config { config := Config{ Profiles: []Profile{ { - Name: "daily", - 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"}, + Name: "daily", + Description: "Creates a MD file in ~/DailyNotes folder in the format YYYY-MM-DD[-vX].md", + Path: "~/DailyNotes", + Type: FileType, + NamePatterns: []ParameterizedText{ + "{{$version := getVersion}}" + + "{{.Year}}-{{.Month}}-{{.Day}}" + + `{{if .ProjectName}}-{{.ProjectName | snakecase }}{{end}}` + + "{{if (gt $version 1)}}v{{$version}}{{end}}" + + ".md", + }, File: File{ Template: `# {{.FileNameWithoutExtension}}