[][src]Module tp_note::config

Collects tp-note's configuration from a configuration file, the command-line parameters. It also reads the clipboard.

Structs

ARGS

Structure to hold the parsed command-line arguments.

Args

Tp-Note is a note-taking-tool and a template system, that consistently synchronizes the note's meta-data with its filename. tp-note collects various information about its environment and the clipboard and stores them in variables. New notes are created by filling these variables in predefined and customizable Tera-templates. In case <path> points to an existing tp-note-file, the note's meta-data is analysed and, if necessary, its filename is modified. For all other file types, tp-note creates a new note that annotates the file <path> points to. If <path> is a directory (or, when omitted the current working directory), a new note is created in that directory. After creation, tp-note launches an external editor of your choice. Although the note's structure follows pandoc-conventions, it is not tied to any specific markup language.

CFG

Reads and parses the configuration file "tp-note.toml". An alternative filename (optionally with absolute path) can be given on the command line with "--config".

CLIPBOARD

Reads the clipboard, if there is any and empties it.

CONFIG_PATH

This is where the confy crate stores the configuration file.

Cfg

Configuration data, deserialized from the configuration-file.

Hyperlink

Represents a hyperlink.

RUNS_ON_CONSOLE

Do we run on a console?

STDIN

Reads the input stream stdin if there is any.

Constants

CONFIG_FILENAME

Crate confy version 0.4 uses this filename by default.

COPY_COUNTER_CLOSING_BRACKETS

Tp-Note may add a counter at the end of the filename when it can not save a file because the name is taken already. This is the closing bracket search pattern. Some examples: "-", "'_'"", "_-","-_", "(" Can be empty.

COPY_COUNTER_EXTRA_SEPARATOR

If the stem of a filename ends with a pattern, that is similar to a copy counter, add this extra separator. Must be -, _ or any combination of both. Shorter looks better.

COPY_COUNTER_OPENING_BRACKETS

Tp-Note may add a counter at the end of the filename when it can not save a file because the name is taken already. This is the opening bracket search pattern. Some examples: "-", "'_'"", "_-","-_", "(" Can be empty.

CURRENT_EXE

Name of this executable (without the Windows ".exe" extension).

EDITOR_ARGS

Default command-line argument list when launching external editor. The editor list is executed item by item until an editor is found. Can be changed in config file.

EDITOR_CONSOLE_ARGS

Default command-line argument list when launching an external editor and no graphical environment is available (DISPLAY=''). This lists console file editors only. The editor list is executed item by item until an editor is found. Can be changed in config file.

ENABLE_EMPTY_CLIPBOARD

Should the clipboard be emptied when tp-note closes? Default value.

ENABLE_READ_CLIPBOARD

By default clipboard support is enabled, can be disabled in config file. A false value here will set ENABLE_EMPTY_CLIPBOARD to false.

EXTENSION_DEFAULT

File extension of to-note files.

NOTE_FILENAME_LEN_MAX

Maximum length of a note's filename in bytes. If a filename-template produces a longer string, it will be truncated.

NOTE_FILE_EXTENSIONS

List of file extensions Tp-Note recognizes as note-files and opens to read their YAML header. Files with other file extensions will not be opened by Tp-Note. Instead, a new note is created with the TMPL_ANNOTATE_CONTENT and TMPL_ANNOTATE_FILENAME templates. It is possible to add file extensions of other markup languages than Markdown here, as long as these files come with a valid YAML meta-data header.

TMPL_ANNOTATE_CONTENT

Default template used when the command-line parameter points to an existing non-.md-file. Can be modified through editing the configuration file. The following variables are defined: {{ file | dirname }}, {{ file | stem }}, {{ file_ext }}, {{ extension_default }} {{ file | tag }}, {{ username }}, {{ lang }}, {{ path }}. In addition all environment variables can be used, e.g. {{ get_env(name=\"LOGNAME\") }} When placed in YAML-front-matter, the filter | json_encode must be appended to each variable. Trick: the expression {% if stdin ~ clipboard != stdin ~ clipboard | heading %} detects if the stdin ~ clipboard content has more than one line of text.

TMPL_ANNOTATE_FILENAME

Filename of a new note, that annotates an existing file on disk given in . Useful variables are: {{ title | sanit(alpha=true) }}, {{ subtitle | sanit }}, {{ extension_default }}. All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. The first non-numerical variable must be the {{ <var>| sanit(alpha) }} variant. Note, that in this filename-template, all variables (expect file | tag) must be filtered by a sanit or sanit(alpha=true) filter.

TMPL_CLIPBOARD_CONTENT

Default template used, when the clipboard or the input stream stdin contains a string and this string has no valid YAML front matter section. The clipboards content is in {{ clipboard }}, its truncated version in {{ clipboard | heading }} When the clipboard contains a hyper-link in markdown format: , its first part is stored in {{ clipboard | linkname }}, the second part in {{ clipboard | linkurl }}. The following variables are defined: {{ dir | stem }}, {{ file | stem }}, {{ file_ext }}, {{ extension_default }} {{ path }}, {{ file | tag }}, {{ username }}. In addition all environment variables can be used, e.g. {{ get_env(name=\"LOGNAME\") }} When placed in YAML-front-matter, the filter | json_encode must be appended to each variable. Trick: the expression {% if clipboard != clipboard | heading %} detects if the clipboard content has more than one line of text.

TMPL_CLIPBOARD_FILENAME

Default filename template used when the stdin ~ clipboard contains a string. Useful variables in this context are: {{ title| sanit }}, {{ subtitle| sanit }}, {{ extension_default }}, All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. The first non-numerical variable must be some {{ <var>| sanit(alpha) }} variant. Note, that in this filename-template, all variables (except now) must be filtered by a sanit or sanit(alpha=true) filter.

TMPL_COPY_CONTENT

Default template used, when the clipboard or the input stream stdin contains a string and one the them HAS a valid YAML front matter section. The clipboards body is in {{ clipboard }}, the header is in {{ clipboard_header }}. The stdin's body is in {{ stdin }}, the header is in {{ stdin_header }}. First the clipboard's header is read. When this is not successful, the stdin header is read. One of the headers must define the title variable, which is available in this script as {{ fm_title }}. Other interpreted variables are {{ fm_subtitle }}, {{ fm_file_ext }} and {{ fm_sort_tag }}. All others are ignored. {{ fm_file_ext }} and {{ fm_sort_tag }} are only defined when they appear in the input stream. When placed in YAML-front-matter, the filter | json_encode must be appended to each variable.

TMPL_COPY_FILENAME

Default filename template used when the stdin or the clipboard contains a string and one of them has a valid YAML header. Useful variables in this context are: {{ title| sanit }}, {{ subtitle| sanit }}, {{ extension_default }}, All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. The first non-numerical variable must be some {{ <var>| sanit(alpha) }} variant. Note, that in this filename-template, all variables (except now) must be filtered by a sanit or sanit(alpha=true) filter.

TMPL_NEW_CONTENT

Default content-template used when the command-line argument is a directory. Can be changed through editing the configuration file. The following variables are defined: {{ sanit | stem }}, {{ file | stem }}, {{ file | ext }}, {{ extension_default }} {{ file | tag }}, {{ username }}, {{ date }}, {{ lang }}, {{ path }}. In addition all environment variables can be used, e.g. {{ get_env(name=\"LOGNAME\") }} When placed in YAML-front-matter, the filter | json_encode must be appended to each variable.

TMPL_NEW_FILENAME

Default filename-template for a new note file on disk. It satisfies the sync criteria for note-meta data in front-matter and filename. Useful variables in this context are: {{ title| sanit }}, {{ subtitle| sanit }}, {{ extension_default }}, All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. The first non-numerical variable must be some {{ <var>| sanit(alpha) }} variant. Note, that in this filename-template, all variables must be filtered by a sanit or sanit(alpha=true) filter.

TMPL_SYNC_FILENAME

Default filename-template to test, if the filename of an existing note file on disk, corresponds to the note's meta data stored in its front matter. If it is not the case, the note's filename will be renamed. Can be modified through editing the configuration file. Useful variables in this context are: {{ tag }} {{ title | sanit }}, {{ subtitle | sanit }}, {{ ext_default }}, All variables also exist in a {{ <var>| sanit(alpha) }} variant: in case its value starts with a number, the string is prepended with '. {{ tag  }} must be the first in line here, then followed by a {{ <var>| sanit(alpha) }} variable. Note, that in this filename-template, all variables (except tag) must be filtered by a sanit or sanit(alpha=true) filter. This is the only template that has access to the {{ tag }} variable. {{ tag }} contains the content of the YAML header variable sort_tag.

VIEWER_ARGS

Default command-line argument list when launching external viewer with --view. Can be changed in config file. The viewer list is executed item by item until an editor is found.

VIEWER_CONSOLE_ARGS

Default command-line argument list when launching external viewer with --view. Can be changed in config file. The viewer list is executed item by item until an editor is found.

Functions

backup_config_file