diff --git a/.gitignore b/.gitignore index 8c86cbce..509b7a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,30 @@ # IDEs/Editors .vscode/ +# Zk specific notebook.db zk + +# Sphinx Docs / Python # +# created by `make docs` for building documentation locally +docs-build/ + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..ed01e550 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,2 @@ +printWidth: 80 +proseWrap: "always" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e281b68e..0821507d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,3 +60,7 @@ Binaries can be created automatically using `make dist-linux` and `make dist-mac Unfortunately, `make dist-macos` must be run manually on both an Apple Silicon and Intel chips. The Linux builds are created using Docker and [these custom images](https://github.com/zk-org/zk-xcompile), which are hosted via [ghcr.io within zk-org](https://github.com/orgs/zk-org/packages/container/package/zk-xcompile). This process is convoluted because `zk` requires CGO with `mattn/go-sqlite3`, which prevents using Go's native cross-compilation. Transitioning to a CGO-free SQLite driver such as [cznic/sqlite](https://gitlab.com/cznic/sqlite) could simplify the distribution process significantly. + +## Documentation + +TODO: add documentation steps for Sphinx docs, after it's all working. diff --git a/Makefile b/Makefile index c826bb59..f002cef4 100644 --- a/Makefile +++ b/Makefile @@ -60,10 +60,17 @@ dist-alpine-i386: && docker run --rm -v "${PWD}":/usr/src/zk -w /usr/src/zk ghcr.io/zk-org/zk-xcompile:alpine-i386 /bin/bash -c 'make alpine' \ && tar -zcvf "zk-${VERSION}-alpine-i386.tar.gz" zk -# Clean build products. +# Clean build and docs products. clean: rm -rf zk* + rm -rf docs-build +### Sphinx Docs ### +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +docs: Makefile + mkdir -p docs-build + sphinx-build -a docs docs-build VERSION := `git describe --tags --match v[0-9]* 2> /dev/null` BUILD := `git rev-parse --short HEAD` diff --git a/docs/.zk/config.toml b/docs/.zk/config.toml new file mode 100644 index 00000000..2f66451d --- /dev/null +++ b/docs/.zk/config.toml @@ -0,0 +1,197 @@ +# zk configuration file +# +# Uncomment the properties you want to customize. + +# NOTE SETTINGS +# +# Defines the default options used when generating new notes. +[note] + +# Language used when writing notes. +# This is used to generate slugs or with date formats. +#language = "en" + +# The default title used for new note, if no `--title` flag is provided. +#default-title = "Untitled" + +# Template used to generate a note's filename, without extension. +#filename = "{{id}}" + +# The file extension used for the notes. +#extension = "md" + +# Template used to generate a note's content. +# If not an absolute path or "~/unix/path", it's relative to .zk/templates/ +template = "default.md" + +# Path globs ignored while indexing existing notes. +#ignore = [ +# "drafts/*", +# "log.md" +#] + +# Configure random ID generation. + +# The charset used for random IDs. You can use: +# * letters: only letters from a to z. +# * numbers: 0 to 9 +# * alphanum: letters + numbers +# * hex: hexadecimal, from a to f and 0 to 9 +# * custom string: will use any character from the provided value +#id-charset = "alphanum" + +# Length of the generated IDs. +#id-length = 4 + +# Letter case for the random IDs, among lower, upper or mixed. +#id-case = "lower" + + +# EXTRA VARIABLES +# +# A dictionary of variables you can use for any custom values when generating +# new notes. They are accessible in templates with {{extra.}} +[extra] + +#key = "value" + + +# GROUP OVERRIDES +# +# You can override global settings from [note] and [extra] for a particular +# group of notes by declaring a [group.""] section. +# +# Specify the list of directories which will automatically belong to the group +# with the optional `paths` property. +# +# Omitting `paths` is equivalent to providing a single path equal to the name of +# the group. This can be useful to quickly declare a group by the name of the +# directory it applies to. + +#[group.""] +#paths = ["", ""] +#[group."".note] +#filename = "{{format-date now}}" +#[group."".extra] +#key = "value" + + +# MARKDOWN SETTINGS +[format.markdown] + +# Format used to generate links between notes. +# Either "wiki", "markdown" or a custom template. Default is "markdown". +#link-format = "wiki" +# Indicates whether a link's path will be percent-encoded. +# Defaults to true for "markdown" format and false for "wiki" format. +#link-encode-path = true +# Indicates whether a link's path file extension will be removed. +# Defaults to true. +#link-drop-extension = true + +# Enable support for #hashtags. +hashtags = true +# Enable support for :colon:separated:tags:. +colon-tags = false +# Enable support for Bear's #multi-word tags# +# Hashtags must be enabled for multi-word tags to work. +multiword-tags = false + + +# EXTERNAL TOOLS +[tool] + +# Default editor used to open notes. When not set, the EDITOR or VISUAL +# environment variables are used. +#editor = "vim" + +# Pager used to scroll through long output. If you want to disable paging +# altogether, set it to an empty string "". +#pager = "less -FIRX" + +# Command used to preview a note during interactive fzf mode. +# Set it to an empty string "" to disable preview. + +# bat is a great tool to render Markdown document with syntax highlighting. +#https://github.com/sharkdp/bat +#fzf-preview = "bat -p --color always {-1}" + + +# LSP +# +# Configure basic editor integration for LSP-compatible editors. +# See https://github.com/zk-org/zk/blob/main/docs/editors-integration.md +# +[lsp] + +[lsp.diagnostics] +# Each diagnostic can have for value: none, hint, info, warning, error + +# Report titles of wiki-links as hints. +#wiki-title = "hint" +# Warn for dead links between notes. +dead-link = "error" + +[lsp.completion] +# Customize the completion pop-up of your LSP client. + +# Show the note title in the completion pop-up, or fallback on its path if empty. +#note-label = "{{title-or-path}}" +# Filter out the completion pop-up using the note title or its path. +#note-filter-text = "{{title}} {{path}}" +# Show the note filename without extension as detail. +#note-detail = "{{filename-stem}}" + + +# NAMED FILTERS +# +# A named filter is a set of note filtering options used frequently together. +# +[filter] + +# Matches the notes created the last two weeks. For example: +# $ zk list recents --limit 15 +# $ zk edit recents --interactive +#recents = "--sort created- --created-after 'last two weeks'" + + +# COMMAND ALIASES +# +# Aliases are user commands called with `zk [] []`. +# +# The alias will be executed with `$SHELL -c`, please refer to your shell's +# man page to see the available syntax. In most shells: +# * $@ can be used to expand all the provided flags and arguments +# * you can pipe commands together with the usual | character +# +[alias] +# Here are a few aliases to get you started. + +# Shortcut to a command. +#ls = "zk list $@" + +# Default flags for an existing command. +#list = "zk list --quiet $@" + +# Edit the last modified note. +#editlast = "zk edit --limit 1 --sort modified- $@" + +# Edit the notes selected interactively among the notes created the last two weeks. +# This alias doesn't take any argument, so we don't use $@. +#recent = "zk edit --sort created- --created-after 'last two weeks' --interactive" + +# Print paths separated with colons for the notes found with the given +# arguments. This can be useful to expand a complex search query into a flag +# taking only paths. For example: +# zk list --link-to "`zk path -m potatoe`" +#path = "zk list --quiet --format {{path}} --delimiter , $@" + +# Show a random note. +#lucky = "zk list --quiet --format full --sort random --limit 1" + +# Returns the Git history for the notes found with the given arguments. +# Note the use of a pipe and the location of $@. +#hist = "zk list --format path --delimiter0 --quiet $@ | xargs -t -0 git log --patch --" + +# Edit this configuration file. +#conf = '$EDITOR "$ZK_NOTEBOOK_DIR/.zk/config.toml"' diff --git a/docs/.zk/templates/default.md b/docs/.zk/templates/default.md new file mode 100644 index 00000000..cb441747 --- /dev/null +++ b/docs/.zk/templates/default.md @@ -0,0 +1,3 @@ +# {{title}} + +{{content}} diff --git a/docs/automation.md b/docs/automation.md deleted file mode 100644 index ae564613..00000000 --- a/docs/automation.md +++ /dev/null @@ -1,10 +0,0 @@ -# Automating frequent tasks - -`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) or [named filters](config-filter.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/zk-org/zk/issues). diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..8aa63b89 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,30 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = "zk" +copyright = "2024, zk-org" +author = "zk-org" +release = "0.14.1" + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ["myst_parser"] +myst_enable_extensions = ["colon_fence", "html_image"] +suppress_warnings = ["myst.xref_missing", "myst.iref_ambiguous"] + +templates_path = ["_templates"] +exclude_patterns = [".zk"] + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = "furo" +html_static_path = ["_static"] +master_doc = "index" diff --git a/docs/config-extra.md b/docs/config-extra.md deleted file mode 100644 index f5d15d73..00000000 --- a/docs/config-extra.md +++ /dev/null @@ -1,43 +0,0 @@ -# Extra user variables - -`zk` is opened for template context extension which can be useful when [creating new notes](note-creation.md), for example: - -* expanding custom metadata (author, subject, etc.) -* modifying a [template](template.md)'s output dynamically depending on the value of an extra variable - -## Static extra variables - -You can declare static extra variables in the [configuration file](config.md)'s `[extra]` section. Each [note group](config-group.md) can have its own `[extra]` section, which may override values from the root section. - -```toml -[extra] -visibility = "public" -author = "Mickaël" - -[group.journal.extra] -visibility = "private" # overrides -``` - -## Dynamic extra variables - -Maybe more useful, you can provide additional extra variables dynamically to `zk new` from the command-line with `--extra`. Multiple variables can be separated by a comma `,`. - -```sh -$ zk new --extra author=Thomas -$ zk new --extra show-header=1,author=Thomas -``` - -## Using extra variables in templates - -After declaring extra variables, you can expand them inside the [template used when creating new notes](template-creation.md), using the usual [Handlebars syntax](template.md). - -```markdown -# {{title}} - -Written by {{extra.author}}. - -{{#if extra.show-header}} -Behold, the mighty dynamic header! -{{/if}} -``` - diff --git a/docs/config-notebook.md b/docs/config-notebook.md deleted file mode 100644 index ce760406..00000000 --- a/docs/config-notebook.md +++ /dev/null @@ -1,15 +0,0 @@ -# Notebook configuration - -The `[notebook]` section from the [configuration file](config.md) is used to set the default notebook directory. -If the path starts with `~` it will be replaced with the user home directory (`$HOME`). This property also supports environment variables. - -```toml -[notebook] -dir = "~/notebook" # same as "$HOME/notebook" -``` - - The following properties are customizable: - -* `dir` (string) - * Path of the default notebook. - * Only available in the global config file (`~/.config/zk/config.toml`). diff --git a/docs/config-alias.md b/docs/config/config-alias.md similarity index 66% rename from docs/config-alias.md rename to docs/config/config-alias.md index d139db62..d6582201 100644 --- a/docs/config-alias.md +++ b/docs/config/config-alias.md @@ -1,43 +1,54 @@ # Command aliases -A command alias is a custom `zk` command which can run another `zk` command or an external program. +A command alias is a custom `zk` command which can run another `zk` command or +an external program. -Declaring your own aliases is a great way to make your experience with `zk` easier and more familiar. With aliases, `zk` becomes a hub capable of launching all the programs you need to manage your [notebook](notebook.md). +Declaring your own aliases is a great way to make your experience with `zk` +easier and more familiar. With aliases, `zk` becomes a hub capable of launching +all the programs you need to manage your [notebook](../notes/notebook.md). ## Configuring aliases -Command aliases are declared in your [configuration file](config.md), under the `[alias]` section. They are executed with [your default shell](tool-shell.md), which allows you to: +Command aliases are declared in your [configuration file](config.md), under the +`[alias]` section. They are executed with [your default shell](tool-shell.md), +which allows you to: -* expand arguments with `$@` or `$*` - * [it is recommended to wrap `$@` in quotes](https://github.com/zk-org/zk/issues/316#issuecomment-1543564168) -* expand environment variables -* run several commands with `&&` -* pipe several commands with `|` +- expand arguments with `$@` or `$*` + - [it is recommended to wrap `$@` in quotes](https://github.com/zk-org/zk/issues/316#issuecomment-1543564168) +- expand environment variables +- run several commands with `&&` +- pipe several commands with `|` -An alias can call other aliases but cannot call itself. This enables you to override the default options of native commands, for example: +An alias can call other aliases but cannot call itself. This enables you to +override the default options of native commands, for example: ```toml [alias] edit = 'zk edit --interactive "$@"' ``` -When running an alias, the `ZK_NOTEBOOK_DIR` environment variable is set to the absolute path of the current notebook. You can use it to run commands working no matter the location of the working directory. +When running an alias, the `ZK_NOTEBOOK_DIR` environment variable is set to the +absolute path of the current notebook. You can use it to run commands working no +matter the location of the working directory. ```toml journal = 'zk new "$ZK_NOTEBOOK_DIR/journal"' ``` -If you need to surround the path with quotes, make sure you use double quotes, otherwise environment variables will not be expanded. +If you need to surround the path with quotes, make sure you use double quotes, +otherwise environment variables will not be expanded. ### `xargs` formula -Calling an external program with a list of note paths using `xargs` is such a common use case that we can extract a reusable alias pattern. +Calling an external program with a list of note paths using `xargs` is such a +common use case that we can extract a reusable alias pattern. ```toml alias = "zk list --quiet --format path --delimiter0 $@ | xargs -0 " ``` -Find more details about these options in [Send notes for processing by other programs](external-processing.md). +Find more details about these options in +[Send notes for processing by other programs](../tips/external-processing.md). ## Collection of useful aliases @@ -53,7 +64,8 @@ n = "zk new $@" ### Edit the last modified note -Suffixing the `modified` sort criterion with `-` orders the notes by *descendent* modification date. +Suffixing the `modified` sort criterion with `-` orders the notes by +_descendent_ modification date. ```toml edlast = "zk edit --limit 1 --sort modified- $@" @@ -61,9 +73,12 @@ edlast = "zk edit --limit 1 --sort modified- $@" ### Edit the notes created during the last two weeks -This command uses `--interactive` to let the user select which notes to actually edit among the recent ones. Note the use of human friendly language for `--created-after`'s argument. +This command uses `--interactive` to let the user select which notes to actually +edit among the recent ones. Note the use of human friendly language for +`--created-after`'s argument. -In this case, additional arguments do not necessarily make sense, so we omit the trailing `$@`. +In this case, additional arguments do not necessarily make sense, so we omit the +trailing `$@`. ```toml recent = "zk edit --sort created- --created-after 'last two weeks' --interactive" @@ -73,7 +88,8 @@ This kind of alias might be more useful as a [named filter](config-filter.md). ### Edit the configuration file -Here's a concrete example using environment variables, in particular `ZK_NOTEBOOK_DIR`. Note the double quotes around the path. +Here's a concrete example using environment variables, in particular +`ZK_NOTEBOOK_DIR`. Note the double quotes around the path. ```toml conf = '$EDITOR "$ZK_NOTEBOOK_DIR/.zk/config.toml"' @@ -81,7 +97,10 @@ conf = '$EDITOR "$ZK_NOTEBOOK_DIR/.zk/config.toml"' ### List paths in a command-line friendly fashion -Use this alias to send a list of space-separated file paths matching the given [filtering criteria](note-filtering.md) to another program. See [send notes for processing by other programs](external-processing.md) for more details. +Use this alias to send a list of space-separated file paths matching the given +[filtering criteria](../notes/note-filtering.md) to another program. See +[send notes for processing by other programs](../tips/external-processing.md) for more +details. ```toml paths = "zk list --quiet --format \"'{{path}}'\" --delimiter ' ' $@" @@ -89,7 +108,8 @@ paths = "zk list --quiet --format \"'{{path}}'\" --delimiter ' ' $@" ### List paths to be used in a parent `zk` command -Similarly, use this alias to expand filtered note paths inside a parent `zk` command taking a comma-separated paths list. +Similarly, use this alias to expand filtered note paths inside a parent `zk` +command taking a comma-separated paths list. ```toml inline = "zk list --quiet --format {{path}} --delimiter , $@" @@ -107,7 +127,8 @@ $ zk list --linked-by "`zk inline journal`" ### Print a random note -Increasing serendipity while using your notebook is important to spark new ideas. The `random` sort criterion is the key to this alias. +Increasing serendipity while using your notebook is important to spark new +ideas. The `random` sort criterion is the key to this alias. ```toml lucky = "zk list --quiet --format full --sort random --limit 1" @@ -115,7 +136,9 @@ lucky = "zk list --quiet --format full --sort random --limit 1" ### Create a note from a free title -If you often create notes with `zk new --title "An interesting concept"`, you will like this alias. Using `"$*"`, you do not need to quote the arguments anymore. +If you often create notes with `zk new --title "An interesting concept"`, you +will like this alias. Using `"$*"`, you do not need to quote the arguments +anymore. ```toml nt = 'zk new --title "$*"' @@ -127,7 +150,8 @@ No more forgotten quotes! ### Create a note and save its path into the clipboard (macOS) -Build upon the previous alias, but instead of editing the created note it will copy the created note's path into the macOS clipboard. +Build upon the previous alias, but instead of editing the created note it will +copy the created note's path into the macOS clipboard. ```toml ntc = 'zk new --print-path --title "$*" | pbcopy' @@ -135,7 +159,8 @@ ntc = 'zk new --print-path --title "$*" | pbcopy' ### Print and sort the word count of selected notes -This will list the notes and their word count sorted by increasing word count. It is useful to spot flimsy notes that you could flesh out. +This will list the notes and their word count sorted by increasing word count. +It is useful to spot flimsy notes that you could flesh out. ```toml wc = "zk list --format '{{word-count}}\t{{title}}' --sort word-count $@" @@ -162,9 +187,12 @@ bl = "zk list --link-to $@" ### Locate unlinked mentions in a note -This alias can help you look for potential new links to establish, by listing every note whose title is mentioned in the note you are working on but which are not already linked to it. +This alias can help you look for potential new links to establish, by listing +every note whose title is mentioned in the note you are working on but which are +not already linked to it. -Note that we are using a single argument `$1` which is repeated for both options. +Note that we are using a single argument `$1` which is repeated for both +options. ```toml unlinked-mentions = "zk list --mentioned-by $1 --no-linked-by $1" @@ -180,7 +208,8 @@ log = "zk list --quiet --format path --delimiter0 $@ | xargs -0 git log --patch ### Saving the changes in the Git repository -This alias does not call `zk` at all! This shows how you can use `zk` as a hub for everything related to your notes. +This alias does not call `zk` at all! This shows how you can use `zk` as a hub +for everything related to your notes. ```toml save = 'git add . && git commit -m "$*"' @@ -190,9 +219,12 @@ Usage: `zk save Expand the note on command aliases` ### Copy/backup selected notes -A more complex example backing up the notes matching the given filtering criteria in a target directory. It creates intermediate directories if needed. +A more complex example backing up the notes matching the given filtering +criteria in a target directory. It creates intermediate directories if needed. -`$1` and `${@:2}` are used to split the arguments between the first one which will be the destination directory, and the remaining arguments which will be used as filtering options. +`$1` and `${@:2}` are used to split the arguments between the first one which +will be the destination directory, and the remaining arguments which will be +used as filtering options. ```toml # macOS @@ -203,4 +235,3 @@ cp = 'mkdir -p "$1" && zk list --quiet --format path --delimiter0 ${@:2} | xargs ``` Usage: `zk cp output/ --created-after 'last two weeks'` - diff --git a/docs/config/config-extra.md b/docs/config/config-extra.md new file mode 100644 index 00000000..fe95df9f --- /dev/null +++ b/docs/config/config-extra.md @@ -0,0 +1,48 @@ +# Extra user variables + +`zk` is opened for template context extension which can be useful when +[creating new notes](../notes/note-creation.md), for example: + +- expanding custom metadata (author, subject, etc.) +- modifying a [template](../notes/template.md)'s output dynamically depending on the + value of an extra variable + +## Static extra variables + +You can declare static extra variables in the [configuration file](config.md)'s +`[extra]` section. Each [note group](config-group.md) can have its own `[extra]` +section, which may override values from the root section. + +```toml +[extra] +visibility = "public" +author = "Mickaël" + +[group.journal.extra] +visibility = "private" # overrides +``` + +## Dynamic extra variables + +Maybe more useful, you can provide additional extra variables dynamically to +`zk new` from the command-line with `--extra`. Multiple variables can be +separated by a comma `,`. + +```sh +$ zk new --extra author=Thomas +$ zk new --extra show-header=1,author=Thomas +``` + +## Using extra variables in templates + +After declaring extra variables, you can expand them inside the +[template used when creating new notes](../notes/template-creation.md), using the usual +[Handlebars syntax](../notes/template.md). + +```markdown +# {{title}} + +Written by {{extra.author}}. + +{{#if extra.show-header}} Behold, the mighty dynamic header! {{/if}} +``` diff --git a/docs/config-filter.md b/docs/config/config-filter.md similarity index 53% rename from docs/config-filter.md rename to docs/config/config-filter.md index 9ec1a896..73f3a03e 100644 --- a/docs/config-filter.md +++ b/docs/config/config-filter.md @@ -1,27 +1,33 @@ # Named filter -A named filter is a set of [note filtering options](note-filtering.md) used frequently together, declared in the [configuration file](config.md). +A named filter is a set of [note filtering options](../notes/note-filtering.md) +used frequently together, declared in the [configuration file](config.md). -For example, if you use regularly the following command to list your most recent notes: +For example, if you use regularly the following command to list your most recent +notes: ```sh $ zk list --sort created- --created-after "last two weeks" ``` -You can create a new named filter in the configuration file to avoid repeating yourself. +You can create a new named filter in the configuration file to avoid repeating +yourself. ```toml [filter] recents = "--sort created- --created-after 'last two weeks'" ``` -Then, you can use the name as an argument of `zk list`, with any additional option. +Then, you can use the name as an argument of `zk list`, with any additional +option. ```sh $ zk list recents --limit 10 ``` -Named filters are similar to [command aliases](config-alias.md), as they simplify frequent commands. However, named filters can be used with any command accepting filtering options. +Named filters are similar to [command aliases](config-alias.md), as they +simplify frequent commands. However, named filters can be used with any command +accepting filtering options. ```sh $ zk edit recents --interactive @@ -29,16 +35,22 @@ $ zk edit recents --interactive ## Filter named after a directory -In filtering commands, named filters take precedence over path arguments. As a nice side effect, this means you can customize the default filtering options for a directory by naming a filter after it. +In filtering commands, named filters take precedence over path arguments. As a +nice side effect, this means you can customize the default filtering options for +a directory by naming a filter after it. -For example, by default `zk` sorts notes by their titles. However, if you keep daily notes under a `journal/` directory, you may want to sort them by creation date instead. You can use the following named filter for this: +For example, by default `zk` sorts notes by their titles. However, if you keep +daily notes under a `journal/` directory, you may want to sort them by creation +date instead. You can use the following named filter for this: ``` [filter] journal = "--sort created journal" ``` -Named filters cannot call themselves recursively, so by adding the `journal` argument to the filter, we are actually selecting the `journal/` directory. This means that the following commands are equivalent: +Named filters cannot call themselves recursively, so by adding the `journal` +argument to the filter, we are actually selecting the `journal/` directory. This +means that the following commands are equivalent: ```sh # Without the filter diff --git a/docs/config-group.md b/docs/config/config-group.md similarity index 50% rename from docs/config-group.md rename to docs/config/config-group.md index 23d56304..280a8d1a 100644 --- a/docs/config-group.md +++ b/docs/config/config-group.md @@ -1,10 +1,16 @@ # Note group -A *group* is a named [configuration section](config.md) used to override [note creation rules](config-note.md) for specific directories. This allows you to use your [notebook](notebook.md) very differently depending on the type of note created. For a practical example, take a look at [maintaining a daily journal](daily-journal.md). +A _group_ is a named [configuration section](config.md) used to override +[note creation rules](config-note.md) for specific directories. This allows you +to use your [notebook](../notes/notebook.md) very differently depending on the type of +note created. For a practical example, take a look at +[maintaining a daily journal](../tips/daily-journal.md). ## Declaring a new group -To add a new group to your configuration file, declare a new `[group.]` section. It takes a single optional property `paths`, which is the list of directories belonging to this group. +To add a new group to your configuration file, declare a new `[group.]` +section. It takes a single optional property `paths`, which is the list of +directories belonging to this group. ```toml [group.journal] @@ -14,14 +20,16 @@ paths = [ ] ``` -You can also use [glob patterns](https://en.wikipedia.org/wiki/Glob_\(programming\)) in `paths`. +You can also use +[glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) in `paths`. ```toml [group.journal] paths = ["journal/*"] ``` -If you omit `paths`, the directory named after the group will be inferred. Note the double quotes when using spaces or slashes for subdirectories. +If you omit `paths`, the directory named after the group will be inferred. Note +the double quotes when using spaces or slashes for subdirectories. ```toml # This will automatically apply to the `citations/web` directory @@ -30,7 +38,8 @@ If you omit `paths`, the directory named after the group will be inferred. Note ## Overriding note configuration and extra variables -You can override the global [note configuration](config-note.md) and [extra user variables](config-extra.md) for a given group. +You can override the global [note configuration](config-note.md) and +[extra user variables](config-extra.md) for a given group. ```toml [group.journal.note] @@ -43,7 +52,8 @@ author = "Mickaël" ## Choose a group dynamically -If you prefer to keep multiple groups in a single directory, you can specify which group to use when creating a new note explicitly. +If you prefer to keep multiple groups in a single directory, you can specify +which group to use when creating a new note explicitly. ```sh $ zk new --group journal diff --git a/docs/config-lsp.md b/docs/config/config-lsp.md similarity index 53% rename from docs/config-lsp.md rename to docs/config/config-lsp.md index fe3371fe..b758aff8 100644 --- a/docs/config-lsp.md +++ b/docs/config/config-lsp.md @@ -1,43 +1,46 @@ # LSP configuration -The `[lsp]` [configuration file](config.md) section provides settings to fine-tune the [LSP editors integration](editors-integration.md). +The `[lsp]` [configuration file](config.md) section provides settings to +fine-tune the [LSP editors integration](../tips/editors-integration.md). ## Completion -Customize how completion items appear in your editor when auto-completing links with the `[lsp.completion]` sub-section. +Customize how completion items appear in your editor when auto-completing links +with the `[lsp.completion]` sub-section. | Setting | Type | Description | -|-----------------------------|------------|---------------------------------------------------------------------------------------| +| --------------------------- | ---------- | ------------------------------------------------------------------------------------- | | `note-label` | `template` | Label displayed in the completion pop-up for each note | | `note-filter-text` | `template` | Text used as a source when filtering the completion pop-up with keystrokes | | `note-detail` | `template` | Additional information about a completion item | | `use-additional-text-edits` | `boolean` | Indicates whether `additionalTextEdits` will be used to remove the trigger characters | -Each key accepts a [template](template.md) with the following context: +Each key accepts a [template](../notes/template.md) with the following context: -| Variable | Type | Description | -|-----------------|----------|--------------------------------------------------------------------| -| `filename` | string | Filename of the note, including its extension | -| `filename-stem` | string | Filename of the note without the file extension | -| `path` | string | File path to the note, relative to the notebook root | -| `abs-path` | string | Absolute file path to the note | -| `rel-path` | string | File path to the note, relative to the current directory | -| `title` | string | Note title | -| `title-or-path` | string | Note title or path if empty | -| `metadata` | map | YAML frontmatter metadata, e.g. `metadata.description`1 | +| Variable | Type | Description | +| --------------- | ------ | ------------------------------------------------------------------ | +| `filename` | string | Filename of the note, including its extension | +| `filename-stem` | string | Filename of the note without the file extension | +| `path` | string | File path to the note, relative to the notebook root | +| `abs-path` | string | Absolute file path to the note | +| `rel-path` | string | File path to the note, relative to the current directory | +| `title` | string | Note title | +| `title-or-path` | string | Note title or path if empty | +| `metadata` | map | YAML frontmatter metadata, e.g. `metadata.description`1 | 1. YAML keys are normalized to lower case. - ## Diagnostics -Use the `[lsp.diagnostics]` sub-section to configure how LSP diagnostics are reported to your editors. Each diagnostic setting can be: +Use the `[lsp.diagnostics]` sub-section to configure how LSP diagnostics are +reported to your editors. Each diagnostic setting can be: -* An empty string or `none` to ignore this diagnostic. -* `hint`, `info`, `warning` or `error` to enable and set the severity of the diagnostic. +- An empty string or `none` to ignore this diagnostic. +- `hint`, `info`, `warning` or `error` to enable and set the severity of the + diagnostic. | Setting | Default | Description | -|--------------|-----------|---------------------------------------------------------------------------| +| ------------ | --------- | ------------------------------------------------------------------------- | | `wiki-title` | `"none"` | Report titles of wiki-links, which is useful if you use IDs for filenames | | `dead-link` | `"error"` | Warn for dead links between notes | diff --git a/docs/config-note.md b/docs/config/config-note.md similarity index 77% rename from docs/config-note.md rename to docs/config/config-note.md index a1371467..d901f3a5 100644 --- a/docs/config-note.md +++ b/docs/config/config-note.md @@ -1,6 +1,6 @@ # Note configuration -The `[note]` section from the [configuration file](config.md) is used to set the [note creation rules](note-creation.md). The following properties are customizable: +The `[note]` section from the [configuration file](config.md) is used to set the [note creation rules](../notes/note-creation.md). The following properties are customizable: * `language` (string) * Two-letters code of the language used when writing notes, e.g. `en`. @@ -8,16 +8,16 @@ The `[note]` section from the [configuration file](config.md) is used to set the * `default-title` (string) * The default title used for new notes when no `--title` option is provided. * `filename` (string) - * [Template](template.md) used to generate the note filename, without its file extension. + * [Template](../notes/template.md) used to generate the note filename, without its file extension. * `extension` (string) * File extension for the generated note. By default, `md` (Markdown) is used. * `template` (string) - * Path to the [template](template.md) used to generate the note content. + * Path to the [template](../notes/template.md) used to generate the note content. * Either an absolute path, or relative to `.zk/templates/`. * `exclude` (list of strings) * List of [path globs](https://en.wikipedia.org/wiki/Glob_\(programming\)) excluded during note indexing. * `id-charset` (string) - * Characters set used to [generate random IDs](note-id.md). + * Characters set used to [generate random IDs](../notes/note-id.md). * You can use: * `letters` for characters from `a` to `z` * `numbers` for characters from `0` to `9` @@ -35,8 +35,8 @@ The `[note]` section from the [configuration file](config.md) is used to set the Here are some common filename patterns you may want to use: * `{{id}}` – e.g. `i2hn8.md` - * Just a [random ID](note-id.md), simple and elegant. - * To use [Neuron](neuron.md)'s ID format, set: + * Just a [random ID](../notes/note-id.md), simple and elegant. + * To use [Neuron](../tips/neuron.md)'s ID format, set: ```toml [note] id-charset = "hex" @@ -44,7 +44,7 @@ Here are some common filename patterns you may want to use: id-case = "lower" ``` * `{{slug title}}` – e.g. `an-interesting-concept.md` - * A [slugified](template.md) version of the title given with `--title`. + * A [slugified](../notes/template.md) version of the title given with `--title`. * Readable and practical for web servers, but fragile in case of renaming. * `{{id}}-{{slug title}}` – e.g. `i2hn8-an-interesting-concept.md` * The best of both worlds? Readable but if you link only with the prefix ID, you can rename without breaking links. @@ -54,4 +54,4 @@ Here are some common filename patterns you may want to use: * The format of [The Archive](https://zettelkasten.de/the-archive/) and [sirupsen's zk](https://github.com/sirupsen/zk). * `{{format-date now '%Y-%m-%d'}}` – e.g. `2009-11-17.md` * Sortable, human-friendly format for a daily journal. - * i.e. [Maintaining a daily journal](daily-journal.md). + * i.e. [Maintaining a daily journal](../tips/daily-journal.md). diff --git a/docs/config/config-notebook.md b/docs/config/config-notebook.md new file mode 100644 index 00000000..99d1d21e --- /dev/null +++ b/docs/config/config-notebook.md @@ -0,0 +1,17 @@ +# Notebook configuration + +The `[notebook]` section from the [configuration file](config.md) is used to set +the default notebook directory. If the path starts with `~` it will be replaced +with the user home directory (`$HOME`). This property also supports environment +variables. + +```toml +[notebook] +dir = "~/notebook" # same as "$HOME/notebook" +``` + +The following properties are customizable: + +- `dir` (string) + - Path of the default notebook. + - Only available in the global config file (`~/.config/zk/config.toml`). diff --git a/docs/config.md b/docs/config/config.md similarity index 88% rename from docs/config.md rename to docs/config/config.md index 77acdfe6..2745587d 100644 --- a/docs/config.md +++ b/docs/config/config.md @@ -1,18 +1,18 @@ -# Configuration file +# The Configuration File -Each [notebook](notebook.md) contains a configuration file used to customize your experience with `zk`. This file is located at `.zk/config.toml` and uses the [TOML format](https://github.com/toml-lang/toml). It is composed of several optional sections: +Each [notebook](../notes/notebook.md) contains a configuration file used to customize your experience with `zk`. This file is located at `.zk/config.toml` and uses the [TOML format](https://github.com/toml-lang/toml). It is composed of several optional sections: * `[notebook]` configures the [default notebook](config-notebook.md) * `[note]` sets the [note creation rules](config-note.md) * `[extra]` contains free [user variables](config-extra.md) which can be expanded in templates * `[group]` defines [note groups](config-group.md) with custom rules -* `[format]` configures the [note format settings](note-format.md), such as Markdown options +* `[format]` configures the [note format settings](../notes/note-format.md), such as Markdown options * `[tool]` customizes interaction with external programs such as: * [your default editor](tool-editor.md) * [your default shell](tool-shell.md) * [your default pager](tool-pager.md) * [`fzf`](tool-fzf.md) -* `[lsp]` setups the [Language Server Protocol settings](config-lsp.md) for [editors integration](editors-integration.md) +* `[lsp]` setups the [Language Server Protocol settings](config-lsp.md) for [editors integration](../tips/editors-integration.md) * `[filter]` declares your [named filters](config-filter.md) * `[alias]` holds your [command aliases](config-alias.md) diff --git a/docs/config/index.rst b/docs/config/index.rst new file mode 100644 index 00000000..7f1cfaf2 --- /dev/null +++ b/docs/config/index.rst @@ -0,0 +1,16 @@ +Configuration +============= + +.. toctree:: + :glob: + :maxdepth: 3 + + The config file + Notebook + Notes + Groups + Aliases + Filters + LSP + Extra + Tools diff --git a/docs/config/tool-editor.md b/docs/config/tool-editor.md new file mode 100644 index 00000000..36284c1a --- /dev/null +++ b/docs/config/tool-editor.md @@ -0,0 +1,17 @@ +# Setting your default editor + +`zk` is not a text editor. Instead, it is designed to interface with your +favorite editor to write your notes. + +You can customize which editor to use either from the +[configuration file](config.md) or environment variables. In order of +precedence, `zk` will use: + +1. `ZK_EDITOR` environment variable +2. `editor` configuration property + ```toml + [tool] + editor = "vim" + ``` +3. `VISUAL` environment variable +4. `EDITOR` environment variable diff --git a/docs/tool-fzf.md b/docs/config/tool-fzf.md similarity index 57% rename from docs/tool-fzf.md rename to docs/config/tool-fzf.md index 00ed8599..e26b22de 100644 --- a/docs/tool-fzf.md +++ b/docs/config/tool-fzf.md @@ -1,16 +1,24 @@ # Integration with `fzf` -[`fzf`](https://github.com/junegunn/fzf) is an awesome and versatile fuzzy finder powering `zk`'s [interactive filtering mode](note-filtering.md). +[`fzf`](https://github.com/junegunn/fzf) is an awesome and versatile fuzzy +finder powering `zk`'s [interactive filtering mode](../notes/note-filtering.md). -Besides the standard [`fzf` configuration options](https://github.com/junegunn/fzf) documented on its website, `zk` offers additional options you can set in the `[tool]` [configuration section](config.md). +Besides the standard +[`fzf` configuration options](https://github.com/junegunn/fzf) documented on its +website, `zk` offers additional options you can set in the `[tool]` +[configuration section](config.md). -If you wish to customize more of `fzf` behavior, [please post a feature request](https://github.com/zk-org/zk/issues). +If you wish to customize more of `fzf` behavior, +[please post a feature request](https://github.com/zk-org/zk/issues). ## Preview command -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. +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. -By default, `zk` uses `cat` for preview, which is a bit boring. A much better option would be to use [`bat`](https://github.com/sharkdp/bat) which supports syntax highlighting. +By default, `zk` uses `cat` for preview, which is a bit boring. A much better +option would be to use [`bat`](https://github.com/sharkdp/bat) which supports +syntax highlighting. ```toml [tool] @@ -26,11 +34,16 @@ fzf-preview = "zk list --quiet --format full --limit 1 {-1}" ## Line format -With the `fzf-line` setting property, you can provide your own [template](template.md) to customize the format of each `fzf` line. The lines are used by `fzf` for the fuzzy matching, so if you want to search in the full note content, do not forget to add `{{body}}` in your custom template. +With the `fzf-line` setting property, you can provide your own +[template](../notes/template.md) to customize the format of each `fzf` line. The lines +are used by `fzf` for the fuzzy matching, so if you want to search in the full +note content, do not forget to add `{{body}}` in your custom template. -The default line template is `{{style "title" title-or-path}} {{style "understate" body}} {{style "understate" (json metadata)}}`. +The default line template is +`{{style "title" title-or-path}} {{style "understate" body}} {{style "understate" (json metadata)}}`. -Here's an example using different colors and showing the list of tags as #hashtags: +Here's an example using different colors and showing the list of tags as +#hashtags: ```toml [tool] @@ -42,7 +55,7 @@ fzf-line = "{{style 'blue' rel-path}}{{#each tags}} #{{this}}{{/each}} {{style ' The following variables are available in the line template. | Variable | Type | Description | -|-----------------|----------|--------------------------------------------------------------------| +| --------------- | -------- | ------------------------------------------------------------------ | | `filename` | string | Filename of the note, including its extension | | `filename-stem` | string | Filename of the note without the file extension | | `path` | string | File path to the note, relative to the notebook root | @@ -61,30 +74,34 @@ The following variables are available in the line template. 1. YAML keys are normalized to lower case. - ## `fzf` options -You can override the default `fzf` options used by `zk` with `fzf-options`. Look at `man fzf` for the list of available options. +You can override the default `fzf` options used by `zk` with `fzf-options`. Look +at `man fzf` for the list of available options. ```toml [tool] fzf-options = "--height 40% --border" ``` -Note that this overrides all the default options used by `zk`, you might want to keep some of them: +Note that this overrides all the default options used by `zk`, you might want to +keep some of them: -* `--tiebreak begin` Prefer matches located at the beginning of the line -* `--exact` Look for exact matches instead of fuzzy ones by default -* `--tabstop 4` Length of tab characters -* `--height 100%` Height of the list relative to the terminal window -* `--layout reverse` Display the input field at the top -* `--no-hscroll` Make sure the path and titles are always visible -* `--color hl:-1,hl+:-1` Don't highlight search terms -* `--preview-window wrap` Enable line wrapping in the preview window +- `--tiebreak begin` Prefer matches located at the beginning of the line +- `--exact` Look for exact matches instead of fuzzy ones by default +- `--tabstop 4` Length of tab characters +- `--height 100%` Height of the list relative to the terminal window +- `--layout reverse` Display the input field at the top +- `--no-hscroll` Make sure the path and titles are always visible +- `--color hl:-1,hl+:-1` Don't highlight search terms +- `--preview-window wrap` Enable line wrapping in the preview window ## Key bindings -When running `fzf` with `zk edit --interactive`, you can [create a new note with the `Ctrl-E` key binding](note-creation.md#search-or-create-with-a-single-command). This binding is customizable with `fzf-bind-new`. You can also disable it by setting it to an empty string (`""`). +When running `fzf` with `zk edit --interactive`, you can +[create a new note with the `Ctrl-E` key binding](../notes/note-creation.md#search-or-create-with-a-single-command). +This binding is customizable with `fzf-bind-new`. You can also disable it by +setting it to an empty string (`""`). ```toml [tool] diff --git a/docs/config/tool-pager.md b/docs/config/tool-pager.md new file mode 100644 index 00000000..e3553dae --- /dev/null +++ b/docs/config/tool-pager.md @@ -0,0 +1,21 @@ +# Setting your default pager + +When `zk`'s output exceeds a certain limit, it is automatically paginated by +your system pager. By default, `less` is used but you may set up your own pager +in the [configuration file](config.md) or environment variables. In order of +precedence, `zk` will use: + +1. `ZK_PAGER` environment variable +2. `pager` configuration property + ```toml + [tool] + pager = "less -FIRX" + ``` +3. `PAGER` environment variable + +## Disable the pager + +If you need to disable paging, you can either: + +- use `--no-pager` +- set the `pager` configuration property to an empty string `""` diff --git a/docs/config/tool-shell.md b/docs/config/tool-shell.md new file mode 100644 index 00000000..87262d8e --- /dev/null +++ b/docs/config/tool-shell.md @@ -0,0 +1,16 @@ +# Setting your default shell + +This is _currently_ not supported on Windows (that defaults always to `cmd`). + +You can customize which shell to use to run aliases and commands either from the +[configuration file](config.md) or environment variables. In order of +precedence, `zk` will use: + +1. `ZK_SHELL` environment variable +2. `shell` configuration property + ```toml + [tool] + shell = "/bin/bash" + ``` +3. `SHELL` environment variable +4. `sh` as fallback diff --git a/docs/config/tools.rst b/docs/config/tools.rst new file mode 100644 index 00000000..d31596a0 --- /dev/null +++ b/docs/config/tools.rst @@ -0,0 +1,13 @@ +Tools +===== + + +.. toctree:: + :glob: + :maxdepth: 3 + + fzf + Pager + Editor + Shell + diff --git a/docs/daily-journal.md b/docs/daily-journal.md deleted file mode 100644 index 494f9d23..00000000 --- a/docs/daily-journal.md +++ /dev/null @@ -1,49 +0,0 @@ -# Maintaining a daily journal - -Let's assume you want to write daily notes named like `2021-02-16.md` in a `journal/daily` sub-directory. This common use case is a good fit for creating a [note group](config-group.md) overriding the default [note creation](note-creation.md) settings. - -First, create a `group` entry in the [configuration file](config.md) to set the note settings for this directory. Refer to the [template syntax reference](template.md) to understand how to use the `{{format-date}}` helper. - -```toml -[group.daily] -# Directories listed here will automatically use this group when creating notes. -paths = ["journal/daily"] - -[group.daily.note] -# %Y-%m-%d is actually the default format, so you could use {{format-date now}} instead. -filename = "{{format-date now '%Y-%m-%d'}}" -extension = "md" -template = "daily.md" -``` - -Next, create a template file under `.zk/templates/daily.md` to render the note content. Here we used the date again to generate a title like "February 16, 2021". - -```markdown -# {{format-date now "long"}} - -What did I do today? -``` - -We are now ready to write today's note! We don't need to set `--title` since the note's title is entirely generated by the template. - -```sh -$ zk new journal/daily -``` - -That is a bit of a mouthful for a command called every day. Would it not be better to just write `zk daily`? We can, by defining a [command alias](config-alias.md) in the [configuration file](config.md). - -```toml -[alias] -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-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. - -If you want to edit today's note, simply use this alias: -```sh -$ zk daily -``` diff --git a/docs/editors-integration.md b/docs/editors-integration.md deleted file mode 100644 index 4f65702e..00000000 --- a/docs/editors-integration.md +++ /dev/null @@ -1,252 +0,0 @@ -# Editors integration - -There are several extensions available to integrate `zk` in your favorite editor: - -* [`zk-nvim`](https://github.com/zk-org/zk-nvim) for Neovim 0.5+ -* [`zk-vscode`](https://github.com/zk-org/zk-vscode) for Visual Studio Code - -## Language Server Protocol - -`zk` ships with a [Language Server](https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/) to provide basic support for any LSP-compatible editor. The currently supported features are: - -* Auto-complete Markdown links with `[[` (setup wiki-links in the [note formats configuration](note-format.md)) -* Auto-complete [hashtags and colon-separated tags](tags.md). -* Preview the content of a note when hovering a link. -* Navigate in your notes by following internal links. -* Create a new note using the current selection as title. -* Diagnostics for dead links and wiki-links titles. -* [And more to come...](https://github.com/zk-org/zk/issues/22) - -You can configure some of these features in your notebook's [configuration file](config-lsp.md). - -### Editor LSP configurations - -To start the Language Server, use the `zk lsp` command. Refer to the following sections for editor-specific examples. [Feel free to share the configuration for your editor](https://github.com/zk-org/zk/issues/22). - -#### Vim and Neovim - -##### Vim and Neovim 0.4 - -With [`coc.nvim`](https://github.com/neoclide/coc.nvim), run `:CocConfig` and add the following in the settings file: - -
coc-settings.json - -```jsonc -{ - // Important, otherwise link completion containing spaces and other special characters won't work. - "suggest.invalidInsertCharacters": [], - - "languageserver": { - "zk": { - "command": "zk", - "args": ["lsp"], - "trace.server": "messages", - "filetypes": ["markdown"] - }, - } -} -``` -
- -Here are some additional useful key bindings and custom commands: - -
~/.config/nvim/init.vim - -```viml -" User command to index the current notebook. -" -" zk.index expects a notebook path as first argument, so we provide the current -" buffer path with expand("%:p"). -command! -nargs=0 ZkIndex :call CocAction("runCommand", "zk.index", expand("%:p")) -nnoremap zi :ZkIndex - -" User command to create and open a new note, to be called like this: -" :ZkNew {"title": "An interesting subject", "dir": "inbox", ...} -" -" Note the concatenation with the "edit" command to open the note right away. -command! -nargs=? ZkNew :exec "edit ".CocAction("runCommand", "zk.new", expand("%:p"), ).path - -" Create a new note after prompting for its title. -nnoremap zn :ZkNew {"title": input("Title: ")} -" Create a new note in the directory journal/daily. -nnoremap zj :ZkNew {"dir": "journal/daily"} -``` -
- -##### Neovim 0.5 built-in LSP client - -Using [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig): - -
~/.config/nvim/init.lua - -```lua -local lspconfig = require('lspconfig') -local configs = require('lspconfig/configs') - -configs.zk = { - default_config = { - cmd = {'zk', 'lsp'}, - filetypes = {'markdown'}, - root_dir = function() - return vim.loop.cwd() - end, - settings = {} - }; -} - -lspconfig.zk.setup({ on_attach = function(client, buffer) - -- Add keybindings here, see https://github.com/neovim/nvim-lspconfig#keybindings-and-completion -end }) -``` -
- -#### Sublime Text - -Install the [Sublime LSP](https://github.com/sublimelsp/LSP) package, then run the **Preferences: LSP Settings** command. Add the following to the settings file: - -
LSP.sublime-settings - -```jsonc -{ - "clients": { - "zk": { - "enabled": true, - "command": ["zk", "lsp"], - "languageId": "markdown", - "scopes": [ "source.markdown" ], - "syntaxes": [ "Packages/MarkdownEditing/Markdown.sublime-syntax" ] - } - } -} -``` -
- -#### Visual Studio Code - -Install the [`zk-vscode`](https://marketplace.visualstudio.com/items?itemName=mickael-menu.zk-vscode) extension from the Marketplace. - -### Custom commands - -Using `zk`'s LSP custom commands, you can call `zk` commands right from your editor. Please refer to your editor's documentation on how to bind keyboard shortcuts to custom LSP commands. - -#### `zk.index` - -This LSP command calls `zk index` to refresh your notebook's index. It can be useful to make sure that the auto-completion is up-to-date. `zk.index` takes two arguments: - -1. A path to a file or directory in the notebook to index. -2.
(Optional) A dictionary of additional options (click to expand) - - | Key | Type | Description | - |---------|---------|-----------------------------------| - | `force` | boolean | Reindexes all the notes when true | -
- -`zk.index` returns a dictionary of indexing statistics. - -#### `zk.new` - -This LSP command calls `zk new` to create a new note. It can be useful to quickly create a new note with a key binding. `zk.new` takes two arguments: - -1. A path to any file or directory in the notebook, to locate it. -2.
(Optional) A dictionary of additional options (click to expand) - - | Key | Type | Description | - |---------------------------|----------------------|----------------------------------------------------------------------------------------------------------------------| - | `title` | string | Title of the new note | - | `content` | string | Initial content of the note | - | `dir` | string | Parent directory, relative to the root of the notebook | - | `group` | string | [Note configuration group](config-group.md) | - | `template` | string | [Custom template used to render the note](template-creation.md) | - | `extra` | dictionary | A dictionary of extra variables to expand in the template | - | `date` | string | A date of creation for the note in natural language, e.g. "tomorrow" | - | `edit` | boolean | When true, the editor will open the newly created note (**not supported by all editors**) | - | `dryRun` | boolean | When true, `zk` will not actually create the note on the file system, but will return its generated content and path | - | `insertLinkAtLocation` | location1 | A location in another note where a link to the new note will be inserted | - | `insertContentAtLocation` | location1 | A location in another note where the content of the new note will be inserted | - - 1. The `location` type is an [LSP Location object](https://microsoft.github.io/language-server-protocol/specification#location), for example: - - ```json - { - "uri":"file:///Users/mickael/notes/9se3.md", - "range": { - "end":{"line": 5, "character":149}, - "start":{"line": 5, "character":137} - } - } - ``` -
- -`zk.new` returns a dictionary with two properties: - -* `path` containing the absolute path to the created note. -* `content` containing the raw content of the created note. - -#### `zk.link` - -This LSP command allows editors to tap into the note linking mechanism. It takes three arguments: - -1. A `path` to any file in the notebook that will be linked to -2. An LSP `location` object that points to where the link will be inserted -3. An optional title of the link. If `title` is not provided, the title of the note will be inserted instead - -`zk.link` returns a JSON object with the path to the linked note, if the linking was successful. - -**Note**: This command is _not_ exposed in the command line. This command is targeted at editor / plugin authors to extend zk functionality. - -#### `zk.list` - -This LSP command calls `zk list` to search a notebook. It takes two arguments: - -1. A path to any file or directory in the notebook, to locate it. -2.
A dictionary of additional options (click to expand) - - | Key | Type | Required? | Description | - | ------------------ | -------------- | ----------- | --------------------------------------------------------------------------------------------------------- | - | `select` | string array | Yes | List of note fields to return1 | - | `hrefs` | string array | No | Find notes matching the given path, including its descendants | - | `limit` | integer | No | Limit the number of notes found | - | `match` | string array | No | Terms to search for in the notes | - | `exactMatch` | boolean | No | (deprecated: use `matchStrategy`) Search for exact occurrences of the `match` argument (case insensitive) | - | `matchStrategy` | string | No | Specify match strategy, which may be "fts" (default), "exact" or "re" | - | `excludeHrefs` | string array | No | Ignore notes matching the given path, including its descendants | - | `tags` | string array | No | Find notes tagged with the given tags | - | `mention` | string array | No | Find notes mentioning the title of the given ones | - | `mentionedBy` | string array | No | Find notes whose title is mentioned in the given ones | - | `linkTo` | string array | No | Find notes which are linking to the given ones | - | `linkedBy` | string array | No | Find notes which are linked by the given ones | - | `orphan` | boolean | No | Find notes which are not linked by any other note | - | `tagless` | boolean | No | Find notes which have no tags | - | `related` | string array | No | Find notes which might be related to the given ones | - | `maxDistance` | integer | No | Maximum distance between two linked notes | - | `recursive` | boolean | No | Follow links recursively | - | `created` | string | No | Find notes created on the given date | - | `createdBefore` | string | No | Find notes created before the given date | - | `createdAfter` | string | No | Find notes created after the given date | - | `modified` | string | No | Find notes modified on the given date | - | `modifiedBefore` | string | No | Find notes modified before the given date | - | `modifiedAfter` | string | No | Find notes modified after the given date | - | `sort` | string array | No | Order the notes by the given criterion | - - 1. As the output of this command might be very verbose and put a heavy load on the LSP client, you need to explicitly set which note fields you want to receive with the `select` option. The following fields are available: `filename`, `filenameStem`, `path`, `absPath`, `title`, `lead`, `body`, `snippets`, `rawContent`, `wordCount`, `tags`, `metadata`, `created`, `modified` and `checksum`. - -
- -`zk.list` returns the found notes as a JSON array. - -#### `zk.tag.list` - -This LSP command calls `zk tag list` to return the list of tags in a notebook. It takes two arguments: - -1. A path to any file or directory in the notebook, to locate it. -2.
(Optional) A dictionary of additional options (click to expand) - - | Key | Type | Required? | Description | - |--------|--------------|-----------|--------------------------------------------------| - | `sort` | string array | No | Order the tags by the given criteria1 | - - 1. The available sort criteria are `name` and `note-count`. You can change the order by appending `-` or `+` to the criterion. - -
- -`zk.tag.list` returns the tags as a JSON array. diff --git a/docs/future-proof.md b/docs/future-proof.md deleted file mode 100644 index 6035c760..00000000 --- a/docs/future-proof.md +++ /dev/null @@ -1,5 +0,0 @@ -# A future-proof notebook - -`zk` is designed to be future-proof and rely on simple [plain text formats](note-format.md) 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. diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index 4f36c5e5..00000000 --- a/docs/getting-started.md +++ /dev/null @@ -1,89 +0,0 @@ -# Getting started with `zk` - -A short introduction showing how to use `zk`. - -## Create a new notebook - -Create a [notebook](notebook.md) to host your notes. You are free to organize your notebook as you want, adding subdirectories if needed. - -```sh -$ zk init my-notes -Initialized a notebook in my-notes - -$ cd my-notes -``` - -## Create your first notes - -Now you are ready to write your very first note. Pick a subject, [create a new note](note-creation.md) and write on! - -```sh -$ zk new --title "An interesting concept" -``` - -You can customize your experience using [custom templates](template.md) to generate many kind of notes. - -
Create a note
- -If you are not sure whether a note already exists for a particular subject, the "search or create" mode might be more appropriate than `zk new`. -It is inspired by [Notational Velocity](https://notational.net/) and enables searching for an existing note or creating a new one in a single action. - -From `zk`'s interactive edit screen, press `Ctrl-E` to create a new note using the current search query as title. - -
Create a note
- -## List existing notes - -After some time, hopefully you will have enough notes to be lost in it. - -To help structure your notebook, you can add [metadata](note-frontmatter.md) (e.g. keywords/tags) to your notes. -You can then use `zk`'s powerful [filtering capabilities](note-filtering.md) to find the notes you need. - -```sh -$ zk list --tag "recipe" --match "pizza -pineapple" -``` -
Format the list output
- -Sort the results however you need with `--sort`. - -
Format the list output
- -`--format` and `--delimiter` offer some versatile formatting options to customize the output. - -
Format the list output
- -`zk` is aware of the links you set between your notes. -Backlinks or outbound links of a note can be revealed by using the link filtering options. -It even supports listing indirect links thanks to `--recursive`. - -
Format the list output
- -`zk` supports an interactive mode powered by [`fzf`](https://github.com/junegunn/fzf) to further filter notes manually. - -
Format the list output
- -## Edit existing notes - -To edit notes with your default editor, use `zk edit`. It supports the same [filtering options](note-filtering.md) as `zk list`. - -```sh -$ zk edit --interactive --match "recipe pizza -pineapple" - -# or with short flags -$ zk edit -i -m "recipe pizza -pineapple" -``` - -
Format the list output
- -## Edit the configuration file - -To customize your experience with `zk`, you may want to edit the [user configuration file](config.md). - -```sh -$ vim .zk/config.toml -``` - -Declaring your own [aliases](config-alias.md) is a great way to make your experience with `zk` easier and more familiar. - -
Format the list output
- diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..f80ad1ec --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. image:: assets/media/zk-black-modern.png + :align: center + :width: 300px + +.. image:: assets/media/screencast.svg + :align: center + +`zk` is a plain text note-taking tool that leverages the power of the command line. + +Let's :doc:`get started `. + +.. toctree:: + :hidden: + :titlesonly: + + GitHub + Neovim Plugin + + config/index + notes/index + tips/index + + diff --git a/docs/note-creation.md b/docs/note-creation.md deleted file mode 100644 index c7a8a225..00000000 --- a/docs/note-creation.md +++ /dev/null @@ -1,30 +0,0 @@ -# Creating a new note - -You can add a new note to a [notebook](notebook.md) using `zk new --title "An interesting concept" []`. - -`zk` automatically generates a filename and initial content according to rules set in your [configuration file](config.md). These settings can be customized per [group of notes](config-group.md) in your notebook, as illustrated in [Maintaining a daily journal](daily-journal.md). - -By default, `zk new` will start [your editor](tool-editor.md) after creating the note. You can choose instead to print the absolute path to the note with `--print-path`, which is more useful for [automation](automation.md). - -## Search or create with a single command - -If you are not sure whether a note already exists for a particular subject, the "search or create" mode might be more appropriate than `zk new`. It is inspired by [Notational Velocity](https://notational.net/) and enables searching for an existing note or creating a new one in a single action. - -This option is available when running `zk edit --interactive`, which spawns [`fzf`](tool-fzf.md) to filter selected notes. From `fzf`, press `Ctrl-E` to create a new note using the current search query as title. - -## Create a note with initial content - -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 --interactive -``` - -Alternatively, you can use the content of a file: - -```sh -$ zk new --interactive < file.txt -``` - diff --git a/docs/note-id.md b/docs/note-id.md deleted file mode 100644 index 32cb918c..00000000 --- a/docs/note-id.md +++ /dev/null @@ -1,20 +0,0 @@ -# Note ID - -Each note is uniquely identified by its path relative to the [notebook](notebook.md)'s root. However, in some cases it is more convenient to refer to a "note ID", which is the unique part of its filename. For example, the note ID of the file `200911172034 An interesting concept.md` is `200911172034`. You could have several notes named "An interesting concept", but only one with the ID `200911172034`. - -The purpose of using a unique identifier in your note filenames is to create stable links between your notes, which will not break even if you change the title of the linked note. [See this reference for more information](https://zettelkasten.de/introduction/#the-unique-identifier). - -There are several flavors of note IDs and `zk` supports most of them. You can set it up in the [note configuration](config-note.md). - -## Random ID - -A random ID enables short and memorable unique identifiers. By default, `zk` is configured to generate random IDs of four alphanumeric characters. I found this to be the sweet spot between an easily memorable and usable ID and enough candidates. This default setting can generate 1 679 616 unique IDs. - -## Timestamp - -Another common ID is a timestamp in the `YYYYMMDDHHMM` shape. This is less readable than a short random ID, but has the added advantage of being sortable by creation date. However, I find this not so useful in practice. - -## Sequential IDs - -Sequential (incremented) IDs are currently not supported by `zk`. They get ugly very quickly when deleting outdated notes and have an irregular shape. - diff --git a/docs/notebook.md b/docs/notebook.md deleted file mode 100644 index bdda17bc..00000000 --- a/docs/notebook.md +++ /dev/null @@ -1,17 +0,0 @@ -# Notebook - -A *notebook* is a directory containing a collection of notes managed by `zk`. Notebooks cannot be nested, but you are free to organize your notes in subdirectories. - -To create a new notebook, simply run `zk init []`. - -Most `zk` commands are operating "Git-style" on the notebook containing the current working directory (or one of its parents). However, you can explicitly set which notebook to use with `--notebook-dir` or the `ZK_NOTEBOOK_DIR` environment variable. Setting `ZK_NOTEBOOK_DIR` in your shell configuration (e.g. `~/.profile`) can be used to define a default notebook which `zk` commands will use when the working directory is not in another notebook. - -If the [default notebook](config-notebook.md) is set it will be used as `ZK_NOTEBOOK_DIR`, unless this environment variable is not already set. - -## Anatomy of a notebook - -Similarly to Git, a notebook is identified by the presence of a `.zk` directory at its root. This directory contains the only `zk`-specific files in your notebook: - -* `.zk/config.toml` is the user [configuration file](config.md) -* `.zk/templates/` contains [user templates](template.md) used when [creating new notes](note-creation.md) -* `.zk/notebook.db` is the SQLite database enabling [powerful search features](note-filtering.md). diff --git a/docs/notes/index.rst b/docs/notes/index.rst new file mode 100644 index 00000000..2f68e59d --- /dev/null +++ b/docs/notes/index.rst @@ -0,0 +1,16 @@ +Notes +===== + +.. toctree:: + :glob: + :maxdepth: 3 + + notebook + note-creation + note-filtering + note-format + note-frontmatter + tags + note-id + templating + diff --git a/docs/notes/note-creation.md b/docs/notes/note-creation.md new file mode 100644 index 00000000..c9e60b08 --- /dev/null +++ b/docs/notes/note-creation.md @@ -0,0 +1,44 @@ +# Creating a new note + +You can add a new note to a [notebook](notebook.md) using +`zk new --title "An interesting concept" []`. + +`zk` automatically generates a filename and initial content according to rules +set in your [configuration file](../config/config.md). These settings can be customized +per [group of notes](../config/config-group.md) in your notebook, as illustrated in +[Maintaining a daily journal](../tips/daily-journal.md). + +By default, `zk new` will start [your editor](../config/tool-editor.md) after creating the +note. You can choose instead to print the absolute path to the note with +`--print-path`, which is more useful for [automation](../tips/automation.md). + +(test)= +## Search or create with a single command + +If you are not sure whether a note already exists for a particular subject, the +"search or create" mode might be more appropriate than `zk new`. It is inspired +by [Notational Velocity](https://notational.net/) and enables searching for an +existing note or creating a new one in a single action. + +This option is available when running `zk edit --interactive`, which spawns +[`fzf`](../config/tool-fzf.md) to filter selected notes. From `fzf`, press `Ctrl-E` to +create a new note using the current search query as title. + +## Create a note with initial content + +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 --interactive +``` + +Alternatively, you can use the content of a file: + +```sh +$ zk new --interactive < file.txt +``` diff --git a/docs/note-filtering.md b/docs/notes/note-filtering.md similarity index 60% rename from docs/note-filtering.md rename to docs/notes/note-filtering.md index 9718cc21..6dd51b19 100644 --- a/docs/note-filtering.md +++ b/docs/notes/note-filtering.md @@ -1,10 +1,15 @@ # Searching and filtering notes -A few commands are built upon `zk`'s powerful note filtering capabilities, such as `edit` and `list`. They accept any option described here. You may also declare [named filters](config-filter.md) in the [configuration file](config.md) for the same set of options you use frequently. +A few commands are built upon `zk`'s powerful note filtering capabilities, such +as `edit` and `list`. They accept any option described here. You may also +declare [named filters](../config/config-filter.md) in the +[configuration file](../config/config.md) for the same set of options you use +frequently. ## Filter by path -All filtering commands take for unique positional argument a list of paths. When set, only the notes matching the given paths will be returned. +All filtering commands take for unique positional argument a list of paths. When +set, only the notes matching the given paths will be returned. You can use it to find all the notes in a directory. @@ -18,19 +23,24 @@ Or specific notes. $ zk edit 200911172034-an-interesting-concept.md ``` -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. +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. ```sh $ zk edit 200911172034 ``` -These rules apply to all the following options, when they expect a `` parameter. +These rules apply to all the following options, when they expect a `` +parameter. ```sh $ zk list --link-to 200911172034 ``` -You can also use a nested `zk` command to pre-filter paths to feed to an option with a `` argument. [See the `inline` command alias example](config-alias.md) for more explanation. +You can also use a nested `zk` command to pre-filter paths to feed to an option +with a `` argument. +[See the `inline` command alias example](../config/config-alias.md) for more +explanation. ```sh # List the notes which have at least one link pointing to them (i.e. not orphans). @@ -40,25 +50,28 @@ $ zk list --exclude "`zk inline --orphan`" $ zk list --linked-by "`zk inline journal`" ``` - ## Search the title or body Use `--match ` (or `-m`) to search through the title and body of notes. The search is powered by different strategies to answer various use cases: -* `fts` (default) uses a [full-text search](https://en.wikipedia.org/wiki/Full-text_search) database to offer near-instant results and advanced search operators. -* `exact` is useful if you need to find patterns containing special characters. -* `re` enables regular expression for advanced use cases. +- `fts` (default) uses a + [full-text search](https://en.wikipedia.org/wiki/Full-text_search) database to + offer near-instant results and advanced search operators. +- `exact` is useful if you need to find patterns containing special characters. +- `re` enables regular expression for advanced use cases. -Change the currently used strategy with `--match-strategy ` (or `-M`). To set the default strategy, you can declare a [custom alias](config-alias.md): +Change the currently used strategy with `--match-strategy ` (or `-M`). +To set the default strategy, you can declare a [custom alias](../config/config-alias.md): ```toml [alias] list = "zk list --match-strategy re $@" ``` -The `--match` option may be given multiple times, where each argument will be combined with a boolean AND. +The `--match` option may be given multiple times, where each argument will be +combined with a boolean AND. For example, @@ -72,10 +85,13 @@ Is equivalent to, $ zk list --tag "recipe" --match "(pizza -pineapple) AND (mushrooms)" ``` - ### Full-text search (`fts`) -The default match strategy is powered by a [full-text search](https://en.wikipedia.org/wiki/Full-text_search) database enabling near-instant results. Queries are not case-sensitive and terms are tokenized, which means that searching for `create` will also match `created` and `creating`. +The default match strategy is powered by a +[full-text search](https://en.wikipedia.org/wiki/Full-text_search) database +enabling near-instant results. Queries are not case-sensitive and terms are +tokenized, which means that searching for `create` will also match `created` and +`creating`. A syntax similar to Google Search is available for advanced search queries. @@ -90,20 +106,24 @@ $ zk list -Mf -m "tesla OR edison" #### Combining terms -By default, the search engine will find the notes containing all the terms in the query, in any order. +By default, the search engine will find the notes containing all the terms in +the query, in any order. ``` "tesla edison" ``` -If you want to find the notes containing any or both of the terms, put `OR` (all caps) or a pipe `|` between them. +If you want to find the notes containing any or both of the terms, put `OR` (all +caps) or a pipe `|` between them. ``` "tesla OR edison" "tesla | edison" ``` -Search for an exact phrase by surrounding it with double quotes. In this case, you will need to single quote the full query if you do not want to escape the double quotes. +Search for an exact phrase by surrounding it with double quotes. In this case, +you will need to single quote the full query if you do not want to escape the +double quotes. ``` 'tesla "alternating current"' @@ -115,7 +135,8 @@ To construct more complex queries, you can group sub-queries with parentheses. "current (tesla OR edison)" ``` -Finally, you can filter out results by excluding a term with `NOT` (all caps) or a `-` prefix. +Finally, you can filter out results by excluding a term with `NOT` (all caps) or +a `-` prefix. ``` "tesla NOT car" @@ -124,7 +145,8 @@ Finally, you can filter out results by excluding a term with `NOT` (all caps) or #### Search in specific fields -If you want to search only in the title or body of notes, prefix a query with `title:` or `body:`. +If you want to search only in the title or body of notes, prefix a query with +`title:` or `body:`. ``` "title: tesla" @@ -139,7 +161,8 @@ Match any term beginning with the given prefix with a wildcard `*`. "edi*" ``` -Prefixing a query with `^` will match notes whose title or body start with the following term. +Prefixing a query with `^` will match notes whose title or body start with the +following term. ``` "title: ^journal" @@ -147,7 +170,9 @@ Prefixing a query with `^` will match notes whose title or body start with the f ### Exact matches (`exact`) -If you need to find patterns containing special characters, such as an `email@addre.ss` or a `[[wiki-link]]`, use the `exact` match strategy. The search will be case-insensitive. +If you need to find patterns containing special characters, such as an +`email@addre.ss` or a `[[wiki-link]]`, use the `exact` match strategy. The +search will be case-insensitive. ```sh $ zk list --match-strategy exact --match "[[link]]" @@ -156,9 +181,13 @@ $ zk list -Me -m "[[link]]" ### Regular expressions (`re`) -For advanced use cases, you can use the `re` match strategy to search the notebook using regular expressions. The supported syntax is similar to the one used by Python or Perl. [See the full reference](https://golang.org/s/re2syntax). +For advanced use cases, you can use the `re` match strategy to search the +notebook using regular expressions. The supported syntax is similar to the one +used by Python or Perl. +[See the full reference](https://golang.org/s/re2syntax). -:warning: Make sure to use quotes to prevent your shell from expanding wildcards. +:warning: Make sure to use quotes to prevent your shell from expanding +wildcards. ```sh # Find notes containing emails. @@ -182,29 +211,34 @@ To match notes having either or both tags, use a pipe `|` or `OR` (all caps). $ zk list --tag "inbox OR todo" ``` -If you want to exclude notes having a particular tag instead, prefix it with `-` or `NOT` (all caps). +If you want to exclude notes having a particular tag instead, prefix it with `-` +or `NOT` (all caps). ```sh $ zk list --tag "NOT done" ``` -Your shell might give you some trouble using the `-` prefix. You can quote it and add an extra space as a workaround, e.g. `--tag " -done"`. +Your shell might give you some trouble using the `-` prefix. You can quote it +and add an extra space as a workaround, e.g. `--tag " -done"`. -You can use glob patterns to match multiple tags. This is particularly useful if you use a separator (e.g. `/`) to group multiple tags under a parent tag. +You can use glob patterns to match multiple tags. This is particularly useful if +you use a separator (e.g. `/`) to group multiple tags under a parent tag. ```sh $ zk list --tag "year/201*" ``` -A useful [notebook housekeeping](notebook-housekeeping.md) feature is to find tags which _do not_ have tags. +A useful [notebook housekeeping](../tips/notebook-housekeeping.md) feature is to find +tags which _do not_ have tags. ```sh -$ zk list --tagless +$ zk list --tagless ``` ## Filter by creation or modification date -To find notes created or modified on a specific day, use `--created ` and `--modified `. They accept a human-friendly date for argument. +To find notes created or modified on a specific day, use `--created ` and +`--modified `. They accept a human-friendly date for argument. ``` --created yesterday @@ -212,7 +246,8 @@ To find notes created or modified on a specific day, use `--created ` and --modified "Feb 3" ``` -You can filter by range instead, using `--created-before`, `--created-after`, `--modified-before` and `--modified-after`. +You can filter by range instead, using `--created-before`, `--created-after`, +`--modified-before` and `--modified-after`. ``` --created-before 10am @@ -222,26 +257,35 @@ You can filter by range instead, using `--created-before`, `--created-after`, `- ## Explore links -You can use the following options to explore the web of links spanning your [notebook](notebook.md). +You can use the following options to explore the web of links spanning your +[notebook](notebook.md). -`--linked-by ` (or `-L`) finds the notes linked by the given one, while `--link-to ` (or `-l`) searches the notes having a link to it (also known as *backlinks*). +`--linked-by ` (or `-L`) finds the notes linked by the given one, while +`--link-to ` (or `-l`) searches the notes having a link to it (also known +as _backlinks_). ``` --linked-by 200911172034 --link-to 200911172034 ``` -These options stop at the first level by default. But you can explore the whole web by adding the `--recursive` (or `-r`) option to find all the notes leading to (or from) a given note. If you feel overwhelmed, limit the distance between two notes with `--max-distance `. +These options stop at the first level by default. But you can explore the whole +web by adding the `--recursive` (or `-r`) option to find all the notes leading +to (or from) a given note. If you feel overwhelmed, limit the distance between +two notes with `--max-distance `. ``` --linked-by 200911172034 --recursive --max-distance 3 ``` -Finally, it can be useful to see which notes have no links pointing to them at all. You can use the `--orphan` option for this. +Finally, it can be useful to see which notes have no links pointing to them at +all. You can use the `--orphan` option for this. ## Find related notes -Part of writing a great notebook is to establish links between related notes. The `--related ` option can help by listing results having a linked note in common, but not yet connected to the note. +Part of writing a great notebook is to establish links between related notes. +The `--related ` option can help by listing results having a linked note +in common, but not yet connected to the note. ``` --related 200911172034 @@ -249,13 +293,19 @@ Part of writing a great notebook is to establish links between related notes. Th ## Locate mentions of other notes -Another great way to look for potential new links is to find every mention of other notes in the note you are currently working on. +Another great way to look for potential new links is to find every mention of +other notes in the note you are currently working on. ``` --mentioned-by 200911172034 ``` -This option will find every note whose title is mentioned in the given note. To refer to a note using several names, you can use the [YAML frontmatter](note-frontmatter.md) to declare additional aliases. For example, a note titled "Artificial Intelligence" might have for aliases "AI" and "robot". This method is compatible with [Obsidian](https://publish.obsidian.md/help/How+to/Add+aliases+to+note). +This option will find every note whose title is mentioned in the given note. To +refer to a note using several names, you can use the +[YAML frontmatter](note-frontmatter.md) to declare additional aliases. For +example, a note titled "Artificial Intelligence" might have for aliases "AI" and +"robot". This method is compatible with +[Obsidian](https://publish.obsidian.md/help/How+to/Add+aliases+to+note). ``` --- @@ -270,7 +320,9 @@ Alternatively, find every note mentioning the given note with `--mention`. --mention 200911172034 ``` -To find only unlinked mentions, pair the `--mentioned-by` and `--mentions` options with `--no-linked-by` (resp. `--no-link-to`) to remove notes which are already linked from the results. +To find only unlinked mentions, pair the `--mentioned-by` and `--mentions` +options with `--no-linked-by` (resp. `--no-link-to`) to remove notes which are +already linked from the results. ``` --mentioned-by 200911172034 --no-linked-by 200911172034 @@ -279,7 +331,9 @@ To find only unlinked mentions, pair the `--mentioned-by` and `--mentions` optio ## Exclude notes from the results -To prevent certain notes from polluting the results, you can explicitly exclude them with `--exclude ` (or `-x`). This is particularly useful when you have a whole directory of notes to be ignored. +To prevent certain notes from polluting the results, you can explicitly exclude +them with `--exclude ` (or `-x`). This is particularly useful when you +have a whole directory of notes to be ignored. ``` -x journal @@ -287,7 +341,8 @@ To prevent certain notes from polluting the results, you can explicitly exclude ## Limit the number of results -If you are only interested into the first few notes, limit the number of results with `--limit ` (or `-n`). +If you are only interested into the first few notes, limit the number of results +with `--limit ` (or `-n`). ``` --limit 20 @@ -297,15 +352,22 @@ Using `-n1` is particularly common when you are expecting only a single result. ## Interactive filtering -A common search flow is to reduce the search scope using `zk`'s filtering options, before selecting manually the notes to process among them. This is especially useful with `zk edit` to avoid opening many unwanted notes with your editor. +A common search flow is to reduce the search scope using `zk`'s filtering +options, before selecting manually the notes to process among them. This is +especially useful with `zk edit` to avoid opening many unwanted notes with your +editor. -Use `--interactive` (or `-i`) to select filtered notes manually. The interactive selection is handled by [`fzf`](tool-fzf.md) which brings a powerful fuzzy matching search into the mix. +Use `--interactive` (or `-i`) to select filtered notes manually. The interactive +selection is handled by [`fzf`](../config/tool-fzf.md) which brings a powerful fuzzy +matching search into the mix. ## Sort the results -After finding matching notes, it might be useful to sort them before processing. The `--sort ` (or `-s`) option is made for that. +After finding matching notes, it might be useful to sort them before processing. +The `--sort ` (or `-s`) option is made for that. -You can add a `+` (ascending) or `-` (descending) suffix to a sort criterion to customize the order. Each criterion has a sensible intrinsic order by default. +You can add a `+` (ascending) or `-` (descending) suffix to a sort criterion to +customize the order. Each criterion has a sensible intrinsic order by default. ``` --sort path @@ -314,11 +376,10 @@ You can add a `+` (ascending) or `-` (descending) suffix to a sort criterion to ``` | Criterion | Shortcut | Order | Description | -|--------------|----------|-------|------------------------------------| +| ------------ | -------- | ----- | ---------------------------------- | | `created` | `c` | `-` | Creation date | | `modified` | `m` | `-` | Modification date | | `path` | `p` | `+` | File path relative to the notebook | | `title` | `t` | `+` | Note title | | `random` | `r` | `+` | Order notes randomly | | `word-count` | `wc` | `+` | Word count in the note | - diff --git a/docs/note-format.md b/docs/notes/note-format.md similarity index 70% rename from docs/note-format.md rename to docs/notes/note-format.md index c4547094..01f38680 100644 --- a/docs/note-format.md +++ b/docs/notes/note-format.md @@ -1,13 +1,16 @@ # Note formats -To keep your notebooks [future-proof](future-proof.md), `zk` uses a simple plain text format for your notes. Only Markdown is supported at the moment, but more formats may be added in the future. +To keep your notebooks [future-proof](../tips/future-proof.md), `zk` uses a simple plain +text format for your notes. Only Markdown is supported at the moment, but more +formats may be added in the future. ## Markdown -You can set up some features of `zk`'s Markdown parser from your [configuration file](config.md), under the `[format.markdown]` section. +You can set up some features of `zk`'s Markdown parser from your +[configuration file](../config/config.md), under the `[format.markdown]` section. | Setting | Default | Description | -|-----------------------|-----------------|--------------------------------------------------------------------------------| +| --------------------- | --------------- | ------------------------------------------------------------------------------ | | `link-format` | `"markdown"` | Format used to generate internal links (`markdown`, `wiki` or custom template) | | `link-encode-path` | `-`1 | Percent-encode paths of generated internal links | | `link-drop-extension` | `true` | Remove the path file extension of generated internal links | @@ -15,13 +18,18 @@ You can set up some features of `zk`'s Markdown parser from your [configuration | `colon-tags` | `false` | Enable `:colon:separated:tags:` support | | `multiword-tags` | `false` | Enable Bear's [`#multi-word tags#`][1]. Hashtags must also be enabled. | -1. Paths are not percent-encoded by default, unless the `link-format` is `markdown`. +1. Paths are not percent-encoded by default, unless the `link-format` is + `markdown`. [1]: https://blog.bear.app/2017/11/bear-tips-how-to-create-multi-word-tags/ ### Customizing the Markdown links generated by `zk` -By default, `zk` will generate regular Markdown links for internal links. If you prefer to use `[[Wiki Links]]` instead, set the `link-format` setting to `wiki`. If you want to override completely the link format, you can also set `link-format` to a [custom template](template.md). For example, to generate a wiki link using an ID from the frontmatter and a title: +By default, `zk` will generate regular Markdown links for internal links. If you +prefer to use `[[Wiki Links]]` instead, set the `link-format` setting to `wiki`. +If you want to override completely the link format, you can also set +`link-format` to a [custom template](template.md). For example, to generate a +wiki link using an ID from the frontmatter and a title: ```toml [format.markdown] @@ -31,7 +39,7 @@ link-format = "[[{{metadata.id}}|{{title}}]]" The following variables are available in the template: | Variable | Type | Description | -|------------|--------|-----------------------------------------------------------| +| ---------- | ------ | --------------------------------------------------------- | | `filename` | string | Filename of the note | | `path` | string | File path to the note, relative to the notebook directory | | `abs-path` | string | Absolute file path to the note | diff --git a/docs/note-frontmatter.md b/docs/notes/note-frontmatter.md similarity index 64% rename from docs/note-frontmatter.md rename to docs/notes/note-frontmatter.md index 2d5abcd0..e432473b 100644 --- a/docs/note-frontmatter.md +++ b/docs/notes/note-frontmatter.md @@ -1,6 +1,9 @@ # YAML frontmatter -Markdown being a simple format, it does not offer any way to attach additional metadata to a note. The community came up with a solution by inserting a YAML header at the top of each note to contain its metadata. This method is widely supported among Zettelkasten softwares, including `zk`. +Markdown being a simple format, it does not offer any way to attach additional +metadata to a note. The community came up with a solution by inserting a YAML +header at the top of each note to contain its metadata. This method is widely +supported among Zettelkasten softwares, including `zk`. ```yaml --- @@ -13,11 +16,13 @@ keywords: [writing, essay, practice] `zk` supports the following metadata: | Key | Description | -|------------|-------------------------------------------------------------| +| ---------- | ----------------------------------------------------------- | | `title` | Title of the note – takes precedence over the first heading | | `date` | Creation date – takes precedence over the file date | | `tags` | List of tags attached to this note | | `keywords` | Alias for `tags` | | `aliases` | Alternative titles for this note, used by `--mention` | -All metadata are indexed and can be printed in `zk list` output, using the template variable `{{metadata.}}`, e.g. `{{metadata.description}}`. The keys are normalized to lower case. +All metadata are indexed and can be printed in `zk list` output, using the +template variable `{{metadata.}}`, e.g. `{{metadata.description}}`. The +keys are normalized to lower case. diff --git a/docs/notes/note-id.md b/docs/notes/note-id.md new file mode 100644 index 00000000..ca30e86c --- /dev/null +++ b/docs/notes/note-id.md @@ -0,0 +1,34 @@ +# Note ID + +Each note is uniquely identified by its path relative to the +[notebook](notebook.md)'s root. However, in some cases it is more convenient to +refer to a "note ID", which is the unique part of its filename. For example, the +note ID of the file `200911172034 An interesting concept.md` is `200911172034`. +You could have several notes named "An interesting concept", but only one with +the ID `200911172034`. + +The purpose of using a unique identifier in your note filenames is to create +stable links between your notes, which will not break even if you change the +title of the linked note. +[See this reference for more information](https://zettelkasten.de/introduction/#the-unique-identifier). + +There are several flavors of note IDs and `zk` supports most of them. You can +set it up in the [note configuration](../config/config-note.md). + +## Random ID + +A random ID enables short and memorable unique identifiers. By default, `zk` is +configured to generate random IDs of four alphanumeric characters. I found this +to be the sweet spot between an easily memorable and usable ID and enough +candidates. This default setting can generate 1 679 616 unique IDs. + +## Timestamp + +Another common ID is a timestamp in the `YYYYMMDDHHMM` shape. This is less +readable than a short random ID, but has the added advantage of being sortable +by creation date. However, I find this not so useful in practice. + +## Sequential IDs + +Sequential (incremented) IDs are currently not supported by `zk`. They get ugly +very quickly when deleting outdated notes and have an irregular shape. diff --git a/docs/notes/notebook.md b/docs/notes/notebook.md new file mode 100644 index 00000000..cbb2450c --- /dev/null +++ b/docs/notes/notebook.md @@ -0,0 +1,29 @@ +# Notebook + +A _notebook_ is a directory containing a collection of notes managed by `zk`. +Notebooks cannot be nested, but you are free to organize your notes in +subdirectories. + +To create a new notebook, simply run `zk init []`. + +Most `zk` commands are operating "Git-style" on the notebook containing the +current working directory (or one of its parents). However, you can explicitly +set which notebook to use with `--notebook-dir` or the `ZK_NOTEBOOK_DIR` +environment variable. Setting `ZK_NOTEBOOK_DIR` in your shell configuration +(e.g. `~/.profile`) can be used to define a default notebook which `zk` commands +will use when the working directory is not in another notebook. + +If the [default notebook](../config/config-notebook.md) is set it will be used as +`ZK_NOTEBOOK_DIR`, unless this environment variable is not already set. + +## Anatomy of a notebook + +Similarly to Git, a notebook is identified by the presence of a `.zk` directory +at its root. This directory contains the only `zk`-specific files in your +notebook: + +- `.zk/config.toml` is the user [configuration file](../config/config.md) +- `.zk/templates/` contains [user templates](template.md) used when + [creating new notes](note-creation.md) +- `.zk/notebook.db` is the SQLite database enabling + [powerful search features](note-filtering.md). diff --git a/docs/tags.md b/docs/notes/tags.md similarity index 60% rename from docs/tags.md rename to docs/notes/tags.md index ec3aee79..33954fc4 100644 --- a/docs/tags.md +++ b/docs/notes/tags.md @@ -1,13 +1,15 @@ # Tags -Tags are a useful way to organize and filter your notes with `zk`, which supports most syntaxes: +Tags are a useful way to organize and filter your notes with `zk`, which +supports most syntaxes: -* `#hashtags` -* `:colon:separated:tags:` ([opt-in](note-format.md)) -* Bear's `#multi-word tags#` ([opt-in](note-format.md)) -* YAML frontmatter (`tags` and `keywords` keys). +- `#hashtags` +- `:colon:separated:tags:` ([opt-in](note-format.md)) +- Bear's `#multi-word tags#` ([opt-in](note-format.md)) +- YAML frontmatter (`tags` and `keywords` keys). -You can filter your notes by their tags using the `--tags` option, as demonstrated in [Searching and filtering notes](note-filtering.md). +You can filter your notes by their tags using the `--tags` option, as +demonstrated in [Searching and filtering notes](note-filtering.md). ```sh $ zk list --tag "inbox OR todo, NOT done" @@ -17,11 +19,11 @@ $ zk list --tag "inbox OR todo, NOT done" You can list all the tags found in your notebook using `zk tag list`. -The following variables are available in the templates used when formatting tags, for example with `zk tag list --format