From c4ed7c05eeef47388275626b771a2fecbbf1c11c Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Mon, 11 Jul 2022 17:22:34 -0500 Subject: [PATCH 1/7] Add explicit flag to read from standard input Fixes bug introduced in #240 where interactive use of `zk new` results in the command sitting indefinitely for user to supply user input. This change introduces an explicit flag to `new` to indicate standard input should be read for the content of the note. The flag is called `-i` on `--input`. The flag name is somewhat confusing as there is a `--no-input` flag at the global level. I propose that we change that flag name to `--no-prompt` as it more accurately describes the option. To maintain backwards compatibility, we define `--no-input` as an alias. --- docs/assets/media/list-format.svg | 4 ++-- docs/daily-journal.md | 4 ++-- docs/external-call.md | 2 +- internal/cli/cmd/new.go | 10 +++++++--- main.go | 2 +- tests/cmd-graph.tesh | 2 +- tests/cmd-index.tesh | 2 +- tests/cmd-init-defaults.tesh | 2 +- tests/cmd-init.tesh | 8 ++++---- tests/cmd-list.tesh | 2 +- tests/cmd-new.tesh | 3 ++- tests/cmd-tag-list.tesh | 2 +- tests/cmd-tag.tesh | 2 +- tests/flag-help.tesh | 2 +- 14 files changed, 26 insertions(+), 21 deletions(-) diff --git a/docs/assets/media/list-format.svg b/docs/assets/media/list-format.svg index 934ebf8f..6d1b8078 100644 --- a/docs/assets/media/list-format.svg +++ b/docs/assets/media/list-format.svg @@ -96,5 +96,5 @@ - $ $ zk list -qn3 $ zk list -qn3 A future-proof notebook future-proof.md (6 days ago) ‣ `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown.Automating frequent tasks automation.md (2 weeks ago) ‣ `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs:Call zk from other programs external-call.md (2 weeks ago) ‣ Calling `zk` from other programs can be useful in a number of situations, such as:$ zk list -qn3 --format full A future-proof notebook future-proof.mdCreated: 02/26/2021Modified: 02/26/2021 `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown. The shape of your [notebook](notebook.md) is entirely up to you, making `zk` flexible enough to be used in a variety of contexts. However, `zk` shines in a Zettelkasten-style notebook with many small interlinked notes.Automating frequent tasks automation.mdCreated: 02/20/2021Modified: 02/20/2021 `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs: * [write command aliases](config-alias.md) for repeated complex commands * [call `zk` from other programs](external-call.md) * [send notes for processing by other programs](external-processing.md) * [create a note with initial content](note-creation.md) from a standard input pipe: If you find out that `zk` does not behave as expected or could communicate better with other programs, [please post an issue](https://github.com/mickael-menu/zk/issues).Call zk from other programs external-call.md Calling `zk` from other programs can be useful in a number of situations, such as: * creating notes from your text editor using a custom shortcut * creating a reference note from the text selected in your web browser * automating periodical maintenance tasks on your [notebook](notebook.md) * displaying the backlinks of a note in a GUI wrapper around `zk` The following options can be useful to make sure `zk` behaves properly in a background context: <!-- TODO: --color=none, --json --> * `--no-input` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output(END) $ zk list -qn5 --format oneline $ zk list -qn5 --format oneline Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)$ zk list -qn5 --format path $ zk list -qn5 --format path future-proof.mdautomation.mdexternal-call.mdconfig-alias.mdconfig.md$ zk list -qn5 --format path --delimiter , $ zk list -qn5 --format path --delimiter , future-proof.md,automation.md,external-call.md,config-alias.md,config.md$ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" $ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" 54 A future-proof notebook88 Automating frequent tasks101 Call zk from other programs1009 Command aliases345 Configuration file$ - \ No newline at end of file + $ $ zk list -qn3 $ zk list -qn3 A future-proof notebook future-proof.md (6 days ago) ‣ `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown.Automating frequent tasks automation.md (2 weeks ago) ‣ `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs:Call zk from other programs external-call.md (2 weeks ago) ‣ Calling `zk` from other programs can be useful in a number of situations, such as:$ zk list -qn3 --format full A future-proof notebook future-proof.mdCreated: 02/26/2021Modified: 02/26/2021 `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown. The shape of your [notebook](notebook.md) is entirely up to you, making `zk` flexible enough to be used in a variety of contexts. However, `zk` shines in a Zettelkasten-style notebook with many small interlinked notes.Automating frequent tasks automation.mdCreated: 02/20/2021Modified: 02/20/2021 `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs: * [write command aliases](config-alias.md) for repeated complex commands * [call `zk` from other programs](external-call.md) * [send notes for processing by other programs](external-processing.md) * [create a note with initial content](note-creation.md) from a standard input pipe: If you find out that `zk` does not behave as expected or could communicate better with other programs, [please post an issue](https://github.com/mickael-menu/zk/issues).Call zk from other programs external-call.md Calling `zk` from other programs can be useful in a number of situations, such as: * creating notes from your text editor using a custom shortcut * creating a reference note from the text selected in your web browser * automating periodical maintenance tasks on your [notebook](notebook.md) * displaying the backlinks of a note in a GUI wrapper around `zk` The following options can be useful to make sure `zk` behaves properly in a background context: <!-- TODO: --color=none, --json --> * `--no-prompt` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output(END) $ zk list -qn5 --format oneline $ zk list -qn5 --format oneline Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)$ zk list -qn5 --format path $ zk list -qn5 --format path future-proof.mdautomation.mdexternal-call.mdconfig-alias.mdconfig.md$ zk list -qn5 --format path --delimiter , $ zk list -qn5 --format path --delimiter , future-proof.md,automation.md,external-call.md,config-alias.md,config.md$ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" $ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" 54 A future-proof notebook88 Automating frequent tasks101 Call zk from other programs1009 Command aliases345 Configuration file$ + diff --git a/docs/daily-journal.md b/docs/daily-journal.md index 517e5ef5..7e9851e8 100644 --- a/docs/daily-journal.md +++ b/docs/daily-journal.md @@ -34,12 +34,12 @@ That is a bit of a mouthful for a command called every day. Would it not be bett ```toml [alias] -daily = 'zk new --no-input "$ZK_NOTEBOOK_DIR/journal/daily"' +daily = 'zk new --no-prompt "$ZK_NOTEBOOK_DIR/journal/daily"' ``` Let's unpack this alias: -* `zk new` will refuse to overwrite notes. If you already created today's note, it will instead ask you if you wish to edit it. Using `--no-input` skips the prompt and edit the existing note right away. +* `zk new` will refuse to overwrite notes. If you already created today's note, it will instead ask you if you wish to edit it. Using `--no-prompt` skips the prompt and edit the existing note right away. * `$ZK_NOTEBOOK_DIR` is set to the absolute path of the current [notebook](notebook.md) when running an alias. Using it allows you to run `zk daily` no matter where you are in the notebook folder hierarchy. * We need to use double quotes around `$ZK_NOTEBOOK_DIR`, otherwise it will not be expanded. diff --git a/docs/external-call.md b/docs/external-call.md index 7568c2d7..4ecf1e7d 100644 --- a/docs/external-call.md +++ b/docs/external-call.md @@ -10,6 +10,6 @@ Calling `zk` from other programs can be useful in a number of situations, such a The following options can be useful to make sure `zk` behaves properly in a background context: -* `--no-input` disables all user prompts and ignores `--interactive` +* `--no-prompt` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output diff --git a/internal/cli/cmd/new.go b/internal/cli/cmd/new.go index 87be4d41..0a1711ec 100644 --- a/internal/cli/cmd/new.go +++ b/internal/cli/cmd/new.go @@ -17,6 +17,7 @@ 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."` + Input bool `short:i help:"Read contents from stdin."` 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."` @@ -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.Input { + content, err = ioutil.ReadAll(os.Stdin) + if err != nil { + return err + } } date := time.Now() diff --git a/main.go b/main.go index f58af44f..5d03494f 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ var root struct { NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."` WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in instead of the current working directory."` - NoInput NoInput `help:"Never prompt or ask for confirmation."` + NoInput NoInput `name:"no-prompt" aliases:"no-input" help:"Never prompt or ask for confirmation."` // ForceInput is a debugging flag overriding the default value of interaction prompts. ForceInput string `hidden xor:"input"` Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."` diff --git a/tests/cmd-graph.tesh b/tests/cmd-graph.tesh index bd97d2a9..a8b49d90 100644 --- a/tests/cmd-graph.tesh +++ b/tests/cmd-graph.tesh @@ -15,7 +15,7 @@ $ zk graph --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > >Formatting > -f, --format=STRING Format of the graph among: json. diff --git a/tests/cmd-index.tesh b/tests/cmd-index.tesh index ef4feb52..efe20c33 100644 --- a/tests/cmd-index.tesh +++ b/tests/cmd-index.tesh @@ -15,7 +15,7 @@ $ zk index --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > > -f, --force Force indexing all the notes. > -v, --verbose Print detailed information about the indexing diff --git a/tests/cmd-init-defaults.tesh b/tests/cmd-init-defaults.tesh index b20af5ab..409f2f81 100644 --- a/tests/cmd-init-defaults.tesh +++ b/tests/cmd-init-defaults.tesh @@ -1,4 +1,4 @@ -$ zk init --no-input 2> /dev/null +$ zk init --no-prompt 2> /dev/null > >Initialized a notebook in {{working-dir}} diff --git a/tests/cmd-init.tesh b/tests/cmd-init.tesh index 29cfee56..13b546aa 100644 --- a/tests/cmd-init.tesh +++ b/tests/cmd-init.tesh @@ -13,10 +13,10 @@ $ zk init --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. # Creates a new notebook in a new directory. -$ zk init --no-input new-dir 2> /dev/null +$ zk init --no-prompt new-dir 2> /dev/null > >Initialized a notebook in {{working-dir}}/new-dir @@ -25,7 +25,7 @@ $ test -f new-dir/.zk/config.toml # Creates a new notebook in an existing directory. $ mkdir existing-dir -$ zk init --no-input existing-dir 2> /dev/null +$ zk init --no-prompt existing-dir 2> /dev/null > >Initialized a notebook in {{working-dir}}/existing-dir @@ -34,7 +34,7 @@ $ test -f existing-dir/.zk/config.toml # Creates a new notebook in the current directory. $ mkdir cur-dir && cd cur-dir -$ zk init --no-input 2> /dev/null +$ zk init --no-prompt 2> /dev/null > >Initialized a notebook in {{working-dir}} diff --git a/tests/cmd-list.tesh b/tests/cmd-list.tesh index 9b4f7a4e..d6ffc3c7 100644 --- a/tests/cmd-list.tesh +++ b/tests/cmd-list.tesh @@ -15,7 +15,7 @@ $ zk list --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > >Formatting > -f, --format=TEMPLATE Pretty print the list using a custom template or one diff --git a/tests/cmd-new.tesh b/tests/cmd-new.tesh index 4db6f84b..5e540fab 100644 --- a/tests/cmd-new.tesh +++ b/tests/cmd-new.tesh @@ -15,8 +15,9 @@ $ zk new --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > +> -i, --input Read contents from stdin. > -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. diff --git a/tests/cmd-tag-list.tesh b/tests/cmd-tag-list.tesh index 2a6909fd..93ce2129 100644 --- a/tests/cmd-tag-list.tesh +++ b/tests/cmd-tag-list.tesh @@ -12,7 +12,7 @@ $ zk tag list --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > >Formatting > -f, --format=TEMPLATE Pretty print the list using a custom template or one diff --git a/tests/cmd-tag.tesh b/tests/cmd-tag.tesh index 4f62c610..6f5fbd4b 100644 --- a/tests/cmd-tag.tesh +++ b/tests/cmd-tag.tesh @@ -15,7 +15,7 @@ $ zk tag --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. # The default command is `tag list`. $ zk tag diff --git a/tests/flag-help.tesh b/tests/flag-help.tesh index f58c2c49..e8970e16 100644 --- a/tests/flag-help.tesh +++ b/tests/flag-help.tesh @@ -25,7 +25,7 @@ $ zk --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-input Never prompt or ask for confirmation. +> --no-prompt Never prompt or ask for confirmation. > >Run "zk --help" for more information on a command. From e2b92255236e310ed1381de0f2caa0b25d4e247d Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Mon, 11 Jul 2022 20:06:22 -0500 Subject: [PATCH 2/7] Remove alias for no-input Apparently, kong `aliases` are only for commands. It did not work as I had expected. At this point, `--no-input` has been removed. If we want to keep it for backwards compatibility, I suppose we could add a new hidden command line arg called `--no-input`. I defer to you for your thoughts. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5d03494f..bda707b7 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ var root struct { NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."` WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in instead of the current working directory."` - NoInput NoInput `name:"no-prompt" aliases:"no-input" help:"Never prompt or ask for confirmation."` + NoInput NoInput `name:"no-prompt" help:"Never prompt or ask for confirmation."` // ForceInput is a debugging flag overriding the default value of interaction prompts. ForceInput string `hidden xor:"input"` Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."` From 3eb9353c8e913139a4a84fe50316f6f4cd2879f5 Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Tue, 12 Jul 2022 17:33:14 -0500 Subject: [PATCH 3/7] Revert "Remove alias for no-input" This reverts commit e2b92255236e310ed1381de0f2caa0b25d4e247d. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index bda707b7..5d03494f 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ var root struct { NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."` WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in instead of the current working directory."` - NoInput NoInput `name:"no-prompt" help:"Never prompt or ask for confirmation."` + NoInput NoInput `name:"no-prompt" aliases:"no-input" help:"Never prompt or ask for confirmation."` // ForceInput is a debugging flag overriding the default value of interaction prompts. ForceInput string `hidden xor:"input"` Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."` From 781fd2943aba75bd0e1c517f307461962cc105d0 Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Tue, 12 Jul 2022 17:33:47 -0500 Subject: [PATCH 4/7] Revert "Add explicit flag to read from standard input" This reverts commit c4ed7c05eeef47388275626b771a2fecbbf1c11c. --- docs/assets/media/list-format.svg | 4 ++-- docs/daily-journal.md | 4 ++-- docs/external-call.md | 2 +- internal/cli/cmd/new.go | 10 +++------- main.go | 2 +- tests/cmd-graph.tesh | 2 +- tests/cmd-index.tesh | 2 +- tests/cmd-init-defaults.tesh | 2 +- tests/cmd-init.tesh | 8 ++++---- tests/cmd-list.tesh | 2 +- tests/cmd-new.tesh | 3 +-- tests/cmd-tag-list.tesh | 2 +- tests/cmd-tag.tesh | 2 +- tests/flag-help.tesh | 2 +- 14 files changed, 21 insertions(+), 26 deletions(-) diff --git a/docs/assets/media/list-format.svg b/docs/assets/media/list-format.svg index 6d1b8078..934ebf8f 100644 --- a/docs/assets/media/list-format.svg +++ b/docs/assets/media/list-format.svg @@ -96,5 +96,5 @@ - $ $ zk list -qn3 $ zk list -qn3 A future-proof notebook future-proof.md (6 days ago) ‣ `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown.Automating frequent tasks automation.md (2 weeks ago) ‣ `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs:Call zk from other programs external-call.md (2 weeks ago) ‣ Calling `zk` from other programs can be useful in a number of situations, such as:$ zk list -qn3 --format full A future-proof notebook future-proof.mdCreated: 02/26/2021Modified: 02/26/2021 `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown. The shape of your [notebook](notebook.md) is entirely up to you, making `zk` flexible enough to be used in a variety of contexts. However, `zk` shines in a Zettelkasten-style notebook with many small interlinked notes.Automating frequent tasks automation.mdCreated: 02/20/2021Modified: 02/20/2021 `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs: * [write command aliases](config-alias.md) for repeated complex commands * [call `zk` from other programs](external-call.md) * [send notes for processing by other programs](external-processing.md) * [create a note with initial content](note-creation.md) from a standard input pipe: If you find out that `zk` does not behave as expected or could communicate better with other programs, [please post an issue](https://github.com/mickael-menu/zk/issues).Call zk from other programs external-call.md Calling `zk` from other programs can be useful in a number of situations, such as: * creating notes from your text editor using a custom shortcut * creating a reference note from the text selected in your web browser * automating periodical maintenance tasks on your [notebook](notebook.md) * displaying the backlinks of a note in a GUI wrapper around `zk` The following options can be useful to make sure `zk` behaves properly in a background context: <!-- TODO: --color=none, --json --> * `--no-prompt` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output(END) $ zk list -qn5 --format oneline $ zk list -qn5 --format oneline Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)$ zk list -qn5 --format path $ zk list -qn5 --format path future-proof.mdautomation.mdexternal-call.mdconfig-alias.mdconfig.md$ zk list -qn5 --format path --delimiter , $ zk list -qn5 --format path --delimiter , future-proof.md,automation.md,external-call.md,config-alias.md,config.md$ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" $ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" 54 A future-proof notebook88 Automating frequent tasks101 Call zk from other programs1009 Command aliases345 Configuration file$ - + $ $ zk list -qn3 $ zk list -qn3 A future-proof notebook future-proof.md (6 days ago) ‣ `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown.Automating frequent tasks automation.md (2 weeks ago) ‣ `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs:Call zk from other programs external-call.md (2 weeks ago) ‣ Calling `zk` from other programs can be useful in a number of situations, such as:$ zk list -qn3 --format full A future-proof notebook future-proof.mdCreated: 02/26/2021Modified: 02/26/2021 `zk` is designed to be future-proof and rely on simple plain text formats such as Markdown. The shape of your [notebook](notebook.md) is entirely up to you, making `zk` flexible enough to be used in a variety of contexts. However, `zk` shines in a Zettelkasten-style notebook with many small interlinked notes.Automating frequent tasks automation.mdCreated: 02/20/2021Modified: 02/20/2021 `zk` was designed with automation in mind and strive to be [a good Unix citizen](https://en.wikipedia.org/wiki/Unix_philosophy). As such, it offers a number of ways to interface with other programs: * [write command aliases](config-alias.md) for repeated complex commands * [call `zk` from other programs](external-call.md) * [send notes for processing by other programs](external-processing.md) * [create a note with initial content](note-creation.md) from a standard input pipe: If you find out that `zk` does not behave as expected or could communicate better with other programs, [please post an issue](https://github.com/mickael-menu/zk/issues).Call zk from other programs external-call.md Calling `zk` from other programs can be useful in a number of situations, such as: * creating notes from your text editor using a custom shortcut * creating a reference note from the text selected in your web browser * automating periodical maintenance tasks on your [notebook](notebook.md) * displaying the backlinks of a note in a GUI wrapper around `zk` The following options can be useful to make sure `zk` behaves properly in a background context: <!-- TODO: --color=none, --json --> * `--no-input` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output(END) $ zk list -qn5 --format oneline $ zk list -qn5 --format oneline Command aliases config-alias.md (2 weeks ago)Configuration file config.md (3 weeks ago)$ zk list -qn5 --format path $ zk list -qn5 --format path future-proof.mdautomation.mdexternal-call.mdconfig-alias.mdconfig.md$ zk list -qn5 --format path --delimiter , $ zk list -qn5 --format path --delimiter , future-proof.md,automation.md,external-call.md,config-alias.md,config.md$ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" $ zk list -qn5 --format "{{word-count}}\t{{style 'green underline' title}}" 54 A future-proof notebook88 Automating frequent tasks101 Call zk from other programs1009 Command aliases345 Configuration file$ + \ No newline at end of file diff --git a/docs/daily-journal.md b/docs/daily-journal.md index 7e9851e8..517e5ef5 100644 --- a/docs/daily-journal.md +++ b/docs/daily-journal.md @@ -34,12 +34,12 @@ That is a bit of a mouthful for a command called every day. Would it not be bett ```toml [alias] -daily = 'zk new --no-prompt "$ZK_NOTEBOOK_DIR/journal/daily"' +daily = 'zk new --no-input "$ZK_NOTEBOOK_DIR/journal/daily"' ``` Let's unpack this alias: -* `zk new` will refuse to overwrite notes. If you already created today's note, it will instead ask you if you wish to edit it. Using `--no-prompt` skips the prompt and edit the existing note right away. +* `zk new` will refuse to overwrite notes. If you already created today's note, it will instead ask you if you wish to edit it. Using `--no-input` skips the prompt and edit the existing note right away. * `$ZK_NOTEBOOK_DIR` is set to the absolute path of the current [notebook](notebook.md) when running an alias. Using it allows you to run `zk daily` no matter where you are in the notebook folder hierarchy. * We need to use double quotes around `$ZK_NOTEBOOK_DIR`, otherwise it will not be expanded. diff --git a/docs/external-call.md b/docs/external-call.md index 4ecf1e7d..7568c2d7 100644 --- a/docs/external-call.md +++ b/docs/external-call.md @@ -10,6 +10,6 @@ Calling `zk` from other programs can be useful in a number of situations, such a The following options can be useful to make sure `zk` behaves properly in a background context: -* `--no-prompt` disables all user prompts and ignores `--interactive` +* `--no-input` disables all user prompts and ignores `--interactive` * `--quiet` reduces unnecessary output diff --git a/internal/cli/cmd/new.go b/internal/cli/cmd/new.go index 0a1711ec..87be4d41 100644 --- a/internal/cli/cmd/new.go +++ b/internal/cli/cmd/new.go @@ -17,7 +17,6 @@ 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."` - Input bool `short:i help:"Read contents from stdin."` 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."` @@ -34,12 +33,9 @@ func (cmd *New) Run(container *cli.Container) error { return err } - var content []byte - if cmd.Input { - content, err = ioutil.ReadAll(os.Stdin) - if err != nil { - return err - } + content, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return err } date := time.Now() diff --git a/main.go b/main.go index 5d03494f..f58af44f 100644 --- a/main.go +++ b/main.go @@ -32,7 +32,7 @@ var root struct { NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."` WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in instead of the current working directory."` - NoInput NoInput `name:"no-prompt" aliases:"no-input" help:"Never prompt or ask for confirmation."` + NoInput NoInput `help:"Never prompt or ask for confirmation."` // ForceInput is a debugging flag overriding the default value of interaction prompts. ForceInput string `hidden xor:"input"` Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."` diff --git a/tests/cmd-graph.tesh b/tests/cmd-graph.tesh index a8b49d90..bd97d2a9 100644 --- a/tests/cmd-graph.tesh +++ b/tests/cmd-graph.tesh @@ -15,7 +15,7 @@ $ zk graph --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > >Formatting > -f, --format=STRING Format of the graph among: json. diff --git a/tests/cmd-index.tesh b/tests/cmd-index.tesh index efe20c33..ef4feb52 100644 --- a/tests/cmd-index.tesh +++ b/tests/cmd-index.tesh @@ -15,7 +15,7 @@ $ zk index --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > > -f, --force Force indexing all the notes. > -v, --verbose Print detailed information about the indexing diff --git a/tests/cmd-init-defaults.tesh b/tests/cmd-init-defaults.tesh index 409f2f81..b20af5ab 100644 --- a/tests/cmd-init-defaults.tesh +++ b/tests/cmd-init-defaults.tesh @@ -1,4 +1,4 @@ -$ zk init --no-prompt 2> /dev/null +$ zk init --no-input 2> /dev/null > >Initialized a notebook in {{working-dir}} diff --git a/tests/cmd-init.tesh b/tests/cmd-init.tesh index 13b546aa..29cfee56 100644 --- a/tests/cmd-init.tesh +++ b/tests/cmd-init.tesh @@ -13,10 +13,10 @@ $ zk init --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. # Creates a new notebook in a new directory. -$ zk init --no-prompt new-dir 2> /dev/null +$ zk init --no-input new-dir 2> /dev/null > >Initialized a notebook in {{working-dir}}/new-dir @@ -25,7 +25,7 @@ $ test -f new-dir/.zk/config.toml # Creates a new notebook in an existing directory. $ mkdir existing-dir -$ zk init --no-prompt existing-dir 2> /dev/null +$ zk init --no-input existing-dir 2> /dev/null > >Initialized a notebook in {{working-dir}}/existing-dir @@ -34,7 +34,7 @@ $ test -f existing-dir/.zk/config.toml # Creates a new notebook in the current directory. $ mkdir cur-dir && cd cur-dir -$ zk init --no-prompt 2> /dev/null +$ zk init --no-input 2> /dev/null > >Initialized a notebook in {{working-dir}} diff --git a/tests/cmd-list.tesh b/tests/cmd-list.tesh index d6ffc3c7..9b4f7a4e 100644 --- a/tests/cmd-list.tesh +++ b/tests/cmd-list.tesh @@ -15,7 +15,7 @@ $ zk list --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > >Formatting > -f, --format=TEMPLATE Pretty print the list using a custom template or one diff --git a/tests/cmd-new.tesh b/tests/cmd-new.tesh index 5e540fab..4db6f84b 100644 --- a/tests/cmd-new.tesh +++ b/tests/cmd-new.tesh @@ -15,9 +15,8 @@ $ zk new --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > -> -i, --input Read contents from stdin. > -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. diff --git a/tests/cmd-tag-list.tesh b/tests/cmd-tag-list.tesh index 93ce2129..2a6909fd 100644 --- a/tests/cmd-tag-list.tesh +++ b/tests/cmd-tag-list.tesh @@ -12,7 +12,7 @@ $ zk tag list --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > >Formatting > -f, --format=TEMPLATE Pretty print the list using a custom template or one diff --git a/tests/cmd-tag.tesh b/tests/cmd-tag.tesh index 6f5fbd4b..4f62c610 100644 --- a/tests/cmd-tag.tesh +++ b/tests/cmd-tag.tesh @@ -15,7 +15,7 @@ $ zk tag --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. # The default command is `tag list`. $ zk tag diff --git a/tests/flag-help.tesh b/tests/flag-help.tesh index e8970e16..f58c2c49 100644 --- a/tests/flag-help.tesh +++ b/tests/flag-help.tesh @@ -25,7 +25,7 @@ $ zk --help > the notebook where commands are run. > -W, --working-dir=PATH Run as if zk was started in instead of the > current working directory. -> --no-prompt Never prompt or ask for confirmation. +> --no-input Never prompt or ask for confirmation. > >Run "zk --help" for more information on a command. From a3b04da81842424a1f08fd3b603ef96c85f9a4e3 Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Tue, 12 Jul 2022 18:19:04 -0500 Subject: [PATCH 5/7] Add `--interactive` flag to `zk new` This option instructs the `new` command to read the initial contents of the note from standard input. This allows the use to pipe or use shell redirection with note creation: ```sh $ zk new --interactive < file.txt $ echo "Initial content" | zk new --interactive ``` --- docs/note-creation.md | 6 ++++++ internal/cli/cmd/new.go | 28 ++++++++++++++++------------ tests/cmd-new.tesh | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/note-creation.md b/docs/note-creation.md index 4e8d9e0c..7c60bef2 100644 --- a/docs/note-creation.md +++ b/docs/note-creation.md @@ -22,3 +22,9 @@ For example, to use the content of the macOS clipboard as the initial content yo $ pbpaste | zk new ``` +Alternatively, use the `--interactive` or `-i` option with `zk new` to redirect standard input to provide initial content for your note: + +```sh +$ zk new --interactive < file.txt +``` + diff --git a/internal/cli/cmd/new.go b/internal/cli/cmd/new.go index 87be4d41..b8890948 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.tesh b/tests/cmd-new.tesh index 4db6f84b..0501e4f8 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. From 78c704477f54420a7e4dcce248cc84a1e74b3f7a Mon Sep 17 00:00:00 2001 From: Pete Kazmier Date: Wed, 13 Jul 2022 06:49:21 -0500 Subject: [PATCH 6/7] Update tests and docs re: `zk new --interactive` --- docs/assets/media/new1.svg | 4 ++-- docs/assets/media/screencast.svg | 2 +- docs/note-creation.md | 6 +++--- tests/cmd-new-template.tesh | 2 +- tests/cmd-new.tesh | 4 ++-- tests/config-note-filename.tesh | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/assets/media/new1.svg b/docs/assets/media/new1.svg index b11c37b3..55d9e07f 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 a89bbb80..f80fee41 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 7c60bef2..c7a8a225 100644 --- a/docs/note-creation.md +++ b/docs/note-creation.md @@ -14,15 +14,15 @@ 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, use the `--interactive` or `-i` option with `zk new` to redirect standard input to provide initial content for your note: +Alternatively, you can use the content of a file: ```sh $ zk new --interactive < file.txt diff --git a/tests/cmd-new-template.tesh b/tests/cmd-new-template.tesh index 6d961220..963a5817 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 0501e4f8..ba6a154e 100644 --- a/tests/cmd-new.tesh +++ b/tests/cmd-new.tesh @@ -104,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 @@ -112,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 6304126f..c336ec7f 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 From ff70097fb79bc96ec628b7489f0580dd71245df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Wed, 13 Jul 2022 14:32:52 +0200 Subject: [PATCH 7/7] Update CHANGELOG --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 760080e8..56cdce71 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