diff --git a/CHANGELOG.md b/CHANGELOG.md index 760080e..56cdce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,16 @@ All notable changes to this project will be documented in this file. - +## Unreleased + +### Changed + +* `zk new` now requires the `--interactive`/`-i` flag to read the note body from a pipe or standard input. [See rational](https://github.com/mickael-menu/zk/pull/242#issuecomment-1182602001). + +### Fixed + +* [#244](https://github.com/mickael-menu/zk/issues/244) Fixed `zk new` waiting for `Ctrl-D` to proceed (contributed by [@pkazmier](https://github.com/mickael-menu/zk/pull/242)). + ## 0.11.0 diff --git a/docs/assets/media/new1.svg b/docs/assets/media/new1.svg index b11c37b..55d9e07 100644 --- a/docs/assets/media/new1.svg +++ b/docs/assets/media/new1.svg @@ -92,5 +92,5 @@ - $ $ echo "I'm writing about it" $ echo "I'm writing about it" | zk new $ echo "I'm writing about it" | zk new --title "Interesting subject" 1 # Interesting subject 1 2 I'm writing about it 3 ~ docs/interesting-subject.md cwd: /Users/mickael/dvpts/mickael/zk-test 1 # Interesting subject cwd: /Users/mickael/dvpts/mickael/zk-test Z $ zk new journal/ 1 # March 05, 2021 2 What did I do today? 3 * docs/journal/2021-03-05.md Z $ - \ No newline at end of file + $ $ echo "I'm writing about it" $ echo "I'm writing about it" | zk new --interactive $ echo "I'm writing about it" | zk new --interactive --title "Interesting subject" 1 # Interesting subject 1 2 I'm writing about it 3 ~ docs/interesting-subject.md cwd: /Users/mickael/dvpts/mickael/zk-test 1 # Interesting subject cwd: /Users/mickael/dvpts/mickael/zk-test Z $ zk new journal/ 1 # March 05, 2021 2 What did I do today? 3 * docs/journal/2021-03-05.md Z $ + diff --git a/docs/assets/media/screencast.svg b/docs/assets/media/screencast.svg index a89bbb8..f80fee4 100644 --- a/docs/assets/media/screencast.svg +++ b/docs/assets/media/screencast.svg @@ -145,5 +145,5 @@ - $ $ echo "I'm writing about it" | zk new --title "Interesting subject" 1 # Interesting subject 1 2 I'm writing about it 3 ~ docs/interesting-subject.md cwd: /Users/mickael/dvpts/mickael/zk 1 # Interesting subject cwd: /Users/mickael/dvpts/mickael/zk Z $ zk list --match "write subject" $ zk list --match "write subject" Interesting subject interesting-subject.md (just now) ‣ I'm writing about itGetting started with zk getting-started.md (2 weeks ago) ‣ …Pick a subject, [create a new note](note-creation.md) and write on! ```sh $ zk new --title "An interesting concept…Found 2 notes$ zk list --match "write OR subject" --limit 5 Extra user variables config-extra.md (2 weeks ago) ‣ …note-creation.md), for example: * expanding custom metadata (author, subject, etc.) * modifying a [template](template.md)'s output dynamically depending…Creating a new note note-creation.md (2 weeks ago) ‣ …sure whether a note already exists for a particular subject, the "search or create" mode might be more appropriate than…Maintaining a daily journal daily-journal.md (2 weeks ago): Found 5 notes$ zk new journal 1 # March 04, 2021 2 What did I do today? 3 * docs/journal/2021-03-04.md Z $ zk edit --interactive --exclude journal > ╭──────────────────────────────────────╮ 26/26 (0) │ │ Ctrl-E: create a note with the quer.. │ │> A future-proof notebook `zk` is de.. │ │ Automating frequent tasks `zk` was.. │ │ Call zk from other programs Callin.. │ │ Command aliases A command alias is.. │ │ Configuration file Each [notebook].. │ │ Creating a new note You can add a .. │ │ Extra user variables `zk` is opene.. │ │ Getting started with zk A short in.. │ │ Integration with fzf [`fzf`](https.. │ │ Interesting subject I'm writing ab.. │ │ Maintaining a daily journal Let's .. │ │ Neuron [Neuron](https://neuron.zet.. │ │ Note ID Each note is uniquely iden.. │ │ Note configuration The `[note]` se.. │ │ Note group A *group* is a named [c.. │ │ Notebook A *notebook* is a directo.. │ │ Notebook housekeeping Tending to y.. │ │ Searching and filtering notes A fe.. │ │ Send notes for processing by other .. │ │ Setting your default editor `zk` i.. │ │ Setting your default pager When `z.. │ │ Styling `zk` supports a `{{style}}.. ╰──────────────────────────────────────╯ 26/26 (0) # A future-proof notebook Ctrl-E: create a note with the quer.. > A future-proof notebook `zk` is de.. `zk` is designed to be future-proof Automating frequent tasks `zk` was.. and rely on simple plain text format Call zk from other programs Callin.. s such as Markdown. Command aliases A command alias is.. Configuration file Each [notebook].. The shape of your [notebook](noteboo Creating a new note You can add a .. k.md) is entirely up to you, making Extra user variables `zk` is opene.. Getting started with zk A short in.. Integration with fzf [`fzf`](https.. Interesting subject I'm writing ab.. Maintaining a daily journal Let's .. Neuron [Neuron](https://neuron.zet.. Note ID Each note is uniquely iden.. Note configuration The `[note]` se.. Note group A *group* is a named [c.. Notebook A *notebook* is a directo.. Notebook housekeeping Tending to y.. Searching and filtering notes A fe.. Send notes for processing by other .. Setting your default editor `zk` i.. Setting your default pager When `z.. > f ╭──────────────────────────────────────╮ 25/26 (0) # A future-proof notebook Call zk from other programs Callin.. and rely on simple plain text format Automating frequent tasks `zk` was.. s such as Markdown. Searching and filtering notes A fe.. k.md) is entirely up to you, making Template context when formatting a .. Template context when creating note.. zk – a plain text note-taking assis.. Styling `zk` supports a `{{style}}.. Template syntax `zk` uses the [Han.. Creating a new note You can add a .. ╰──────────────────────────────────────╯> fz ╭──────────────────────────────────────╮ 6/26 (0) # A future-proof notebook > Integration with fzf [`fzf`](https.. `zk` is designed to be future-proof Configuration file Each [notebook].. and rely on simple plain text format Notebook housekeeping Tending to y.. s such as Markdown. Creating a new note You can add a .. Command aliases A command alias is.. The shape of your [notebook](noteboo ╰──────────────────────────────────────╯ 6/26 (0) # Integration with `fzf` 1/25> Integration with fzf [`fzf`](https.. [`fzf`](https://github.com/junegunn/ Configuration file Each [notebook].. fzf) is an awesome and versatile fuz Notebook housekeeping Tending to y.. zy finder powering `zk`'s [interacti Creating a new note You can add a .. ve filtering mode](note-filtering.md Searching and filtering notes A fe.. Besides the standard [`fzf` configur ation options](https://github.com/ju negunn/fzf) documented on its websit e, `zk` offers additional options yo u can set in the `[tool]` [configura tion section](config.md). If you wish to customize more of `fz f` behavior, [please post a feature request](https://github.com/mickael- menu/zk/issues). ## Preview command You can customize the command used t o preview a note with `fzf-preview` 1 # Integration with fzf 2 `fzf` is an awesome and versatile fuzzy finder powering zk's interactive filtering mode . 4 Besides the standard `fzf` configuration options documented on its website, zk offers additional options you can set in the [tool] configuration section. 5 6 If you wish to customize more of fzf behavior, please post a feature request. 7 8 ## Preview command 9 10 You can customize the command used to preview a note with fzf-preview. The special placeholder {-1} will be expanded to the note file path. 11 12 By default, zk uses cat for preview, which is a bit boring. A much better option would be to use `bat` which supports syntax highlighting. 13 14 ```toml docs/tool-fzf.md $ zk edit --interactive --created-after "one week ago" 4/4 (0) │ │ March 04, 2021 What did I do today.. │ │ │ │ 4/4 (0) # A future-proof notebook Interesting subject I'm writing ab.. and rely on simple plain text format March 04, 2021 What did I do today.. s such as Markdown. The shape of your [notebook](noteboo k.md) is entirely up to you, making > N ╭──────────────────────────────────────╮ 1/4 (0) # A future-proof notebook > Notebook housekeeping Tending to y.. `zk` is designed to be future-proof and rely on simple plain text format s such as Markdown. 1/4 (0) # Notebook housekeeping 1/26> Notebook housekeeping Tending to y.. Tending to your notes does not only mean writing. You need to keep your ## Find related notes To surf your notebook with ease, mak e sure to link all related notes tog ether. You can list notes which coul d be good candidates for a new link with the `--related` [filtering opti on](note-filtering.md). ```sh $ zk list --related note.md ``` This returns notes which are not con nected to the given note, but with a t least one linked note in common. ## Find flimsy notes > Ne ╭──────────────────────────────────────╮ 0/4 (0) > New ╭──────────────────────────────────────╮> New n ╭──────────────────────────────────────╮> New no ╭──────────────────────────────────────╮> New not ╭──────────────────────────────────────╮> New note ╭──────────────────────────────────────╮ 1 # New note 2 docs/new-note.md > New note% $ zk list --link-to note-id.md $ zk list --link-to note-id.md Neuron neuron.md (2 weeks ago) ‣ using the [same settings as Neuron](https://neuron.zettel.page/id.html) to generate the [note IDs](note-id.md) in the [note configuration](config-note.md) Note configuration config-note.md (2 weeks ago) ‣ Characters set used to [generate random IDs](note-id.md). ‣ Just a [random ID](note-id.md), simple and elegant. Searching and filtering notes note-filtering.md (2 weeks ago) ‣ It works fine with only a path prefix as well. This is useful when you have a [note ID](note-id.md) prefix, but not the full file path. Found 3 notes $ zk list --link-to note-id.md --format oneline $ zk list --link-to note-id.md --format oneline Note configuration config-note.md (2 weeks ago)Searching and filtering notes note-filtering.md (2 weeks ago)Found 3 notes$ zk list --link-to note-id.md --format oneline --recursive $ zk list --link-to note-id.md --format oneline --recursive --max-distance 2 $ zk list --link-to note-id.md --format oneline --recursive --max-distance 2 Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)Integration with fzf tool-fzf.md (2 weeks ago)Neuron neuron.md (2 weeks ago)Note group config-group.md (2 weeks ago)Notebook notebook.md (2 weeks ago)Notebook housekeeping notebook-housekeeping.md (5 days ago)Send notes for processing by other programs external-processing.md (2 weeks ago)Template syntax template.md (2 weeks ago)zk – a plain text note-taking assistant README.md (3 weeks ago)Found 13 notes$ zk list --format "{{word-count}}\t{{title}}" --sort word-count --limit 10 $ zk list --format "{{word-count}}\t{{title}}" --sort word-count --limit 10 3 New note7 Interesting subject10 March 04, 202154 A future-proof notebook69 Setting your default editor88 Automating frequent tasks93 Setting your default pager101 Call zk from other programs106 zk – a plain text note-taking assistant117 NotebookFound 10 notes$ vim .zk/config.toml 1 [note] 1 filename = "{{slug title}}" 2 template = "default.md" 4 [group.journal.note] 5 filename = "{{date now}}" 6 template = "journal.md" 8 [tool] 9 editor = "nvim" 10 fzf-preview = "bat -p --theme Nord --color always {-1}" 12 [alias] docs/.zk/config.toml 12 [note] 11 filename = "{{slug title}}" 10 template = "default.md" 8 [group.journal.note] 7 filename = "{{date now}}" 4 [tool] 3 editor = "nvim" 2 fzf-preview = "bat -p --theme Nord --color always {-1}" 13 [alias] 13 [note] 12 filename = "{{slug title}}" 11 template = "default.md" 10 9 [group.journal.note] 8 filename = "{{date now}}" 7 template = "journal.md" 6 5 [tool] 4 editor = "nvim" 3 fzf-preview = "bat -p --theme Nord --color always {-1}" 1 [alias] 14 -- INSERT -- 14 wc = "zk list --quiet --format '{{word-count}}\t{{title}}' --sort word- count --limit 10 $@" count --limit 10 $@" count --limit 10 $@" "docs/.zk/config.toml" $ zk wc $ zk wc $ zk wc --exclude journal --limit 5 $ zk wc --exclude journal --limit 5 $ + $ $ echo "I'm writing about it" | zk new --interactive --title "Interesting subject" 1 # Interesting subject 1 2 I'm writing about it 3 ~ docs/interesting-subject.md cwd: /Users/mickael/dvpts/mickael/zk 1 # Interesting subject cwd: /Users/mickael/dvpts/mickael/zk Z $ zk list --match "write subject" $ zk list --match "write subject" Interesting subject interesting-subject.md (just now) ‣ I'm writing about itGetting started with zk getting-started.md (2 weeks ago) ‣ …Pick a subject, [create a new note](note-creation.md) and write on! ```sh $ zk new --title "An interesting concept…Found 2 notes$ zk list --match "write OR subject" --limit 5 Extra user variables config-extra.md (2 weeks ago) ‣ …note-creation.md), for example: * expanding custom metadata (author, subject, etc.) * modifying a [template](template.md)'s output dynamically depending…Creating a new note note-creation.md (2 weeks ago) ‣ …sure whether a note already exists for a particular subject, the "search or create" mode might be more appropriate than…Maintaining a daily journal daily-journal.md (2 weeks ago): Found 5 notes$ zk new journal 1 # March 04, 2021 2 What did I do today? 3 * docs/journal/2021-03-04.md Z $ zk edit --interactive --exclude journal > ╭──────────────────────────────────────╮ 26/26 (0) │ │ Ctrl-E: create a note with the quer.. │ │> A future-proof notebook `zk` is de.. │ │ Automating frequent tasks `zk` was.. │ │ Call zk from other programs Callin.. │ │ Command aliases A command alias is.. │ │ Configuration file Each [notebook].. │ │ Creating a new note You can add a .. │ │ Extra user variables `zk` is opene.. │ │ Getting started with zk A short in.. │ │ Integration with fzf [`fzf`](https.. │ │ Interesting subject I'm writing ab.. │ │ Maintaining a daily journal Let's .. │ │ Neuron [Neuron](https://neuron.zet.. │ │ Note ID Each note is uniquely iden.. │ │ Note configuration The `[note]` se.. │ │ Note group A *group* is a named [c.. │ │ Notebook A *notebook* is a directo.. │ │ Notebook housekeeping Tending to y.. │ │ Searching and filtering notes A fe.. │ │ Send notes for processing by other .. │ │ Setting your default editor `zk` i.. │ │ Setting your default pager When `z.. │ │ Styling `zk` supports a `{{style}}.. ╰──────────────────────────────────────╯ 26/26 (0) # A future-proof notebook Ctrl-E: create a note with the quer.. > A future-proof notebook `zk` is de.. `zk` is designed to be future-proof Automating frequent tasks `zk` was.. and rely on simple plain text format Call zk from other programs Callin.. s such as Markdown. Command aliases A command alias is.. Configuration file Each [notebook].. The shape of your [notebook](noteboo Creating a new note You can add a .. k.md) is entirely up to you, making Extra user variables `zk` is opene.. Getting started with zk A short in.. Integration with fzf [`fzf`](https.. Interesting subject I'm writing ab.. Maintaining a daily journal Let's .. Neuron [Neuron](https://neuron.zet.. Note ID Each note is uniquely iden.. Note configuration The `[note]` se.. Note group A *group* is a named [c.. Notebook A *notebook* is a directo.. Notebook housekeeping Tending to y.. Searching and filtering notes A fe.. Send notes for processing by other .. Setting your default editor `zk` i.. Setting your default pager When `z.. > f ╭──────────────────────────────────────╮ 25/26 (0) # A future-proof notebook Call zk from other programs Callin.. and rely on simple plain text format Automating frequent tasks `zk` was.. s such as Markdown. Searching and filtering notes A fe.. k.md) is entirely up to you, making Template context when formatting a .. Template context when creating note.. zk – a plain text note-taking assis.. Styling `zk` supports a `{{style}}.. Template syntax `zk` uses the [Han.. Creating a new note You can add a .. ╰──────────────────────────────────────╯> fz ╭──────────────────────────────────────╮ 6/26 (0) # A future-proof notebook > Integration with fzf [`fzf`](https.. `zk` is designed to be future-proof Configuration file Each [notebook].. and rely on simple plain text format Notebook housekeeping Tending to y.. s such as Markdown. Creating a new note You can add a .. Command aliases A command alias is.. The shape of your [notebook](noteboo ╰──────────────────────────────────────╯ 6/26 (0) # Integration with `fzf` 1/25> Integration with fzf [`fzf`](https.. [`fzf`](https://github.com/junegunn/ Configuration file Each [notebook].. fzf) is an awesome and versatile fuz Notebook housekeeping Tending to y.. zy finder powering `zk`'s [interacti Creating a new note You can add a .. ve filtering mode](note-filtering.md Searching and filtering notes A fe.. Besides the standard [`fzf` configur ation options](https://github.com/ju negunn/fzf) documented on its websit e, `zk` offers additional options yo u can set in the `[tool]` [configura tion section](config.md). If you wish to customize more of `fz f` behavior, [please post a feature request](https://github.com/mickael- menu/zk/issues). ## Preview command You can customize the command used t o preview a note with `fzf-preview` 1 # Integration with fzf 2 `fzf` is an awesome and versatile fuzzy finder powering zk's interactive filtering mode . 4 Besides the standard `fzf` configuration options documented on its website, zk offers additional options you can set in the [tool] configuration section. 5 6 If you wish to customize more of fzf behavior, please post a feature request. 7 8 ## Preview command 9 10 You can customize the command used to preview a note with fzf-preview. The special placeholder {-1} will be expanded to the note file path. 11 12 By default, zk uses cat for preview, which is a bit boring. A much better option would be to use `bat` which supports syntax highlighting. 13 14 ```toml docs/tool-fzf.md $ zk edit --interactive --created-after "one week ago" 4/4 (0) │ │ March 04, 2021 What did I do today.. │ │ │ │ 4/4 (0) # A future-proof notebook Interesting subject I'm writing ab.. and rely on simple plain text format March 04, 2021 What did I do today.. s such as Markdown. The shape of your [notebook](noteboo k.md) is entirely up to you, making > N ╭──────────────────────────────────────╮ 1/4 (0) # A future-proof notebook > Notebook housekeeping Tending to y.. `zk` is designed to be future-proof and rely on simple plain text format s such as Markdown. 1/4 (0) # Notebook housekeeping 1/26> Notebook housekeeping Tending to y.. Tending to your notes does not only mean writing. You need to keep your ## Find related notes To surf your notebook with ease, mak e sure to link all related notes tog ether. You can list notes which coul d be good candidates for a new link with the `--related` [filtering opti on](note-filtering.md). ```sh $ zk list --related note.md ``` This returns notes which are not con nected to the given note, but with a t least one linked note in common. ## Find flimsy notes > Ne ╭──────────────────────────────────────╮ 0/4 (0) > New ╭──────────────────────────────────────╮> New n ╭──────────────────────────────────────╮> New no ╭──────────────────────────────────────╮> New not ╭──────────────────────────────────────╮> New note ╭──────────────────────────────────────╮ 1 # New note 2 docs/new-note.md > New note% $ zk list --link-to note-id.md $ zk list --link-to note-id.md Neuron neuron.md (2 weeks ago) ‣ using the [same settings as Neuron](https://neuron.zettel.page/id.html) to generate the [note IDs](note-id.md) in the [note configuration](config-note.md) Note configuration config-note.md (2 weeks ago) ‣ Characters set used to [generate random IDs](note-id.md). ‣ Just a [random ID](note-id.md), simple and elegant. Searching and filtering notes note-filtering.md (2 weeks ago) ‣ It works fine with only a path prefix as well. This is useful when you have a [note ID](note-id.md) prefix, but not the full file path. Found 3 notes $ zk list --link-to note-id.md --format oneline $ zk list --link-to note-id.md --format oneline Note configuration config-note.md (2 weeks ago)Searching and filtering notes note-filtering.md (2 weeks ago)Found 3 notes$ zk list --link-to note-id.md --format oneline --recursive $ zk list --link-to note-id.md --format oneline --recursive --max-distance 2 $ zk list --link-to note-id.md --format oneline --recursive --max-distance 2 Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)Integration with fzf tool-fzf.md (2 weeks ago)Neuron neuron.md (2 weeks ago)Note group config-group.md (2 weeks ago)Notebook notebook.md (2 weeks ago)Notebook housekeeping notebook-housekeeping.md (5 days ago)Send notes for processing by other programs external-processing.md (2 weeks ago)Template syntax template.md (2 weeks ago)zk – a plain text note-taking assistant README.md (3 weeks ago)Found 13 notes$ zk list --format "{{word-count}}\t{{title}}" --sort word-count --limit 10 $ zk list --format "{{word-count}}\t{{title}}" --sort word-count --limit 10 3 New note7 Interesting subject10 March 04, 202154 A future-proof notebook69 Setting your default editor88 Automating frequent tasks93 Setting your default pager101 Call zk from other programs106 zk – a plain text note-taking assistant117 NotebookFound 10 notes$ vim .zk/config.toml 1 [note] 1 filename = "{{slug title}}" 2 template = "default.md" 4 [group.journal.note] 5 filename = "{{date now}}" 6 template = "journal.md" 8 [tool] 9 editor = "nvim" 10 fzf-preview = "bat -p --theme Nord --color always {-1}" 12 [alias] docs/.zk/config.toml 12 [note] 11 filename = "{{slug title}}" 10 template = "default.md" 8 [group.journal.note] 7 filename = "{{date now}}" 4 [tool] 3 editor = "nvim" 2 fzf-preview = "bat -p --theme Nord --color always {-1}" 13 [alias] 13 [note] 12 filename = "{{slug title}}" 11 template = "default.md" 10 9 [group.journal.note] 8 filename = "{{date now}}" 7 template = "journal.md" 6 5 [tool] 4 editor = "nvim" 3 fzf-preview = "bat -p --theme Nord --color always {-1}" 1 [alias] 14 -- INSERT -- 14 wc = "zk list --quiet --format '{{word-count}}\t{{title}}' --sort word- count --limit 10 $@" count --limit 10 $@" count --limit 10 $@" "docs/.zk/config.toml" $ zk wc $ zk wc $ zk wc --exclude journal --limit 5 $ zk wc --exclude journal --limit 5 $ diff --git a/docs/note-creation.md b/docs/note-creation.md index 4e8d9e0..c7a8a22 100644 --- a/docs/note-creation.md +++ b/docs/note-creation.md @@ -14,11 +14,17 @@ This option is available when running `zk edit --interactive`, which spawns [`fz ## Create a note with initial content -Initial content can be fed to the template through a standard input pipe, which will be expandable with the `{{content}}` [template variable](template-creation.md). +Initial content can be fed to the template through standard input using `zk new --interactive`, which will be expandable with the `{{content}}` [template variable](template-creation.md). For example, to use the content of the macOS clipboard as the initial content you can run: ```sh -$ pbpaste | zk new +$ pbpaste | zk new --interactive +``` + +Alternatively, you can use the content of a file: + +```sh +$ zk new --interactive < file.txt ``` diff --git a/internal/cli/cmd/new.go b/internal/cli/cmd/new.go index 87be4d4..b889094 100644 --- a/internal/cli/cmd/new.go +++ b/internal/cli/cmd/new.go @@ -16,15 +16,16 @@ import ( // New adds a new note to the notebook. type New struct { - Directory string `arg optional default:"." help:"Directory in which to create the note."` - Title string `short:t placeholder:TITLE help:"Title of the new note."` - Date string ` placeholder:DATE help:"Set the current date."` - Group string `short:g placeholder:NAME help:"Name of the config group this note belongs to. Takes precedence over the config of the directory."` - Extra map[string]string ` help:"Extra variables passed to the templates." mapsep:","` - Template string ` placeholder:PATH help:"Custom template used to render the note."` - PrintPath bool `short:p help:"Print the path of the created note instead of editing it."` - DryRun bool `short:n help:"Don't actually create the note. Instead, prints its content on stdout and the generated path on stderr."` - ID string ` placeholder:ID help:"Skip id generation and use provided value."` + Directory string `arg optional default:"." help:"Directory in which to create the note."` + Interactive bool `short:i help:"Read contents from standard input."` + Title string `short:t placeholder:TITLE help:"Title of the new note."` + Date string ` placeholder:DATE help:"Set the current date."` + Group string `short:g placeholder:NAME help:"Name of the config group this note belongs to. Takes precedence over the config of the directory."` + Extra map[string]string ` help:"Extra variables passed to the templates." mapsep:","` + Template string ` placeholder:PATH help:"Custom template used to render the note."` + PrintPath bool `short:p help:"Print the path of the created note instead of editing it."` + DryRun bool `short:n help:"Don't actually create the note. Instead, prints its content on stdout and the generated path on stderr."` + ID string ` placeholder:ID help:"Skip id generation and use provided value."` } func (cmd *New) Run(container *cli.Container) error { @@ -33,9 +34,12 @@ func (cmd *New) Run(container *cli.Container) error { return err } - content, err := ioutil.ReadAll(os.Stdin) - if err != nil { - return err + var content []byte + if cmd.Interactive { + content, err = ioutil.ReadAll(os.Stdin) + if err != nil { + return err + } } date := time.Now() diff --git a/tests/cmd-new-template.tesh b/tests/cmd-new-template.tesh index 6d96122..963a581 100644 --- a/tests/cmd-new-template.tesh +++ b/tests/cmd-new-template.tesh @@ -3,7 +3,7 @@ $ cd new $ mkdir "a dir" # Test Handlebars template variables. -$ echo "Piped content" | zk new --group handlebars --title "Note title" --date "January 2nd" --dry-run "a dir" +$ echo "Piped content" | zk new --interactive --group handlebars --title "Note title" --date "January 2nd" --dry-run "a dir" >id: {{match "[a-z0-9]{4}"}} >title: Note title >content: Piped content diff --git a/tests/cmd-new.tesh b/tests/cmd-new.tesh index 4db6f84..ba6a154 100644 --- a/tests/cmd-new.tesh +++ b/tests/cmd-new.tesh @@ -17,6 +17,7 @@ $ zk new --help > current working directory. > --no-input Never prompt or ask for confirmation. > +> -i, --interactive Read contents from standard input. > -t, --title=TITLE Title of the new note. > --date=DATE Set the current date. > -g, --group=NAME Name of the config group this note belongs to. @@ -103,7 +104,7 @@ $ zk new -n --title "Dry run" 2>{{working-dir}}/dry-run.md # Pipe content in a new note. -$ echo "Content of the note" | EDITOR=cat zk new --title "Piped note" +$ echo "Content of the note" | EDITOR=cat zk new --interactive --title "Piped note" ># Piped note > >Content of the note @@ -111,7 +112,7 @@ $ echo "Content of the note" | EDITOR=cat zk new --title "Piped note" # Redirect file to standard input when creating a new note. $ echo "Content of the note" > input -$ EDITOR=cat zk new --title "Note from redirected input" < input +$ EDITOR=cat zk new --interactive --title "Note from redirected input" < input ># Note from redirected input > >Content of the note diff --git a/tests/config-note-filename.tesh b/tests/config-note-filename.tesh index 6304126..c336ec7 100644 --- a/tests/config-note-filename.tesh +++ b/tests/config-note-filename.tesh @@ -17,7 +17,7 @@ $ zk new --title "A new note" --date "January 5th" --dry-run # Test the filename Handlebars variables. $ mkdir "a dir" $ echo "[note]\n filename = '\{{title}},\{{content}},\{{date now \"%m-%d\"}},\{{json extra}}'" > .zk/config.toml -$ echo "Piped content" | zk new --title "A new note" --date "January 5th" --extra key=value --dry-run +$ echo "Piped content" | zk new --interactive --title "A new note" --date "January 5th" --extra key=value --dry-run 2>{{working-dir}}/A new note,Piped content 2>,01-05,{"key":"value"}.md $ echo "[note]\n filename = '\{{id}},\{{dir}},\{{json extra}},\{{env.ZK_NOTEBOOK_DIR}}'" > .zk/config.toml