keg

package module
v0.0.0-...-7e2beaa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

README

🌳 KEG Commands

GoDoc License

This keg Bonzai branch contains all KEG related commands, most of which are exported so they can be composed individually if preferred.

Install

This command can be installed as a standalone program or composed into a Bonzai command tree.

Standalone

go install github.com/rwxrob/keg/cmd/keg@latest

Or if you prefer (easier to type)

go install github.com/rwxrob/keg/cmd/kn@latest

Composed

package z

import (
	Z "github.com/rwxrob/bonzai/z"
	"github.com/rwxrob/keg"
)

var Cmd = &Z.Cmd{
	Name:     `z`,
	Commands: []*Z.Cmd{help.Cmd, keg.Cmd},
}

Tab Completion

To activate bash completion just use the complete -C option from your .bashrc or command line. There is no messy sourcing required. All the completion is done by the program itself.

complete -C keg keg
complete -C kn kn

If you don't have bash or tab completion check use the shortcut commands instead.

Embedded Documentation

All documentation (like manual pages) has been embedded into the source code of the application. See the source or run the program with help to access it.

Command Line Usage

keg help
kn help

Configuration

map - map of all local keg ids pointing to their directories (like PATH)

Variables

current - current keg from map

Documentation

Index

Examples

Constants

View Source
const IsoDateExpStr = `\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\dZ`
View Source
const IsoDateFmt = `2006-01-02 15:04:05Z`

Variables

View Source
var Cmd = &Z.Cmd{
	Name:      `keg`,
	Aliases:   []string{`kn`},
	Summary:   `manage knowledge exchange graphs (KEG)`,
	Version:   `v0.1.0`,
	Copyright: `Copyright 2022 Robert S Muhlestein`,
	License:   `Apache-2.0`,
	Site:      `rwxrob.tv`,
	Source:    `git@github.com:rwxrob/keg.git`,
	Issues:    `github.com/rwxrob/keg/issues`,

	Commands: []*Z.Cmd{
		editCmd, help.Cmd, conf.Cmd, vars.Cmd,
		dexCmd, createCmd, currentCmd, dirCmd, deleteCmd,
		latestCmd, titleCmd, initCmd,
	},

	Shortcuts: Z.ArgMap{
		`set`: {`var`, `set`},
	},

	ConfVars: true,

	Description: `
		The {{cmd .Name}} command is for personal and public knowledge
		management as a Knowledge Exchange Graph (sometimes called "personal
		knowledge graph" or "zettelkasten"). Using {{cmd .Name}} you can
		create and share knowledge on the free, decentralized,
		protocol-agnostic, world-wide, Knowledge Exchange Grid.

		Run {{cmd "init"}} inside of a new directory to get started with
		a new keg. After editing the {{pre "keg"}} file you can create your
		first node with {{cmd "create"}}.

		For more about the emerging KEG 2023-01 specification and how to
		create content that complies for knowledge exchange and publication
		(while we work more on linting and validation within the {{cmd .Name}}
		command) have a look at https://github.com/rwxrob/keg-spec

		`,
}
View Source
var DefaultInfoFile string
View Source
var DefaultZeroNode string
View Source
var LatestDexEntryExp = regexp.MustCompile(
	`^\* (\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\dZ) \[(.*)\]\(/(\d+)\)$`,
)
View Source
var NodePaths = _fs.IntDirs

NodePaths returns a list of node directory paths contained in the keg root directory path passed. Paths returns are fully qualified and cleaned. Only directories with valid integer node IDs will be recognized. Empty slice is returned if kegroot doesn't point to directory containing node directories with integer names.

The lowest and highest integer names are returned as well to help determine what to name a new directory.

File and directories that do not have an integer name will be ignored.

Functions

func ImportNode

func ImportNode(from, to, nodeid string) error

ImportNode moves the nodedir into the KEG directory for the kegid giving it the nodeid name. Import will fail if the given nodeid already existing the the target KEG.

func MakeDex

func MakeDex(kegdir string) error

MakeDex calls ScanDex and writes (or overwrites) the output to the reserved dex node file within the kegdir passed. File-level locking is attempted using the go-internal/lockedfile (used by Go itself). Both a friendly markdown file reverse sorted by time of last update (latest.md) and a tab-delimited file sorted numerically by node ID (nodes.tsv) are created.

func MkTempNode

func MkTempNode() (string, error)

MkTempNode creates a text node directory containing a README.md file within a directory created with os.MkdirTemp and returns a full path to the README.md file itself. Directory names are always prefixed with keg-node.

func Publish

func Publish(kegpath string) error

Publish publishes the keg at kegpath location to its distribution targets listed in the keg file under "publish." Currently, this only involves looking for a .git directory and if found doing a git push. Git commit messages are always based on the latest node title without any verb.

func UpdateUpdated

func UpdateUpdated(kegpath string) error

UpdateUpdated sets the updated YAML field in the keg info file.

func Updated

func Updated(kegpath string) (*time.Time, error)

Updated parses the most recent change time in the dex/node.md file (the first line) and returns the time stamp it contains as a time.Time. If a time stamp could not be determined returns time.

func UpdatedString

func UpdatedString(kegpath string) string

UpdatedString returns Updated time as a string or an empty string if there is a error.

Example
package main

import (
	"fmt"

	"github.com/rwxrob/keg"
)

func main() {
	fmt.Println(keg.UpdatedString(`testdata/samplekeg`))
}
Output:

2022-11-17 18:34:10Z

Types

type Dex

type Dex []DexEntry

Dex is a collection of DexEntry structs. This allows mapping methods for its serialization to different output formats.

Example (Json)
package main

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/rwxrob/keg"
)

func main() {
	date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC)
	d := keg.DexEntry{U: date, N: 2, T: `Some title`}
	byt, err := json.Marshal(d)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(byt))
}
Output:

{"U":"2022-12-10T06:10:04Z","T":"Some title","N":2}
Example (String)
package main

import (
	"fmt"
	"time"

	"github.com/rwxrob/keg"
)

func main() {
	date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC)
	d := keg.DexEntry{U: date, N: 2, T: `Some title`}
	fmt.Println(d)
	fmt.Println(d.MD())
}
Output:

* 2022-12-10 06:10:04Z [Some title](/2)
* 2022-12-10 06:10:04Z [Some title](/2)
Example (Tsv)
package main

import (
	"fmt"
	"time"

	"github.com/rwxrob/keg"
)

func main() {
	date := time.Date(2022, 12, 10, 6, 10, 4, 0, time.UTC)
	d := keg.DexEntry{U: date, N: 2, T: `Some title`}
	fmt.Println(d.TSV())
}
Output:

2	2022-12-10 06:10:04Z	Some title

func ParseDex

func ParseDex(in any) (*Dex, error)

ParseDex parses any input valid for to.String into a Dex pointer. FIXME: replace regular expression with pegn.Scanner instead

func ReadDex

func ReadDex(kegdir string) (*Dex, error)

ReadDex reads an existing dex/latest.md dex and returns it.

func ScanDex

func ScanDex(kegdir string) (*Dex, error)

ScanDex takes the target path to a keg root directory returns a Dex object.

func (Dex) AsIncludes

func (e Dex) AsIncludes() string

AsIncludes renders the entire Dex as a KEGML include list (markdown bulleted list) and cab be useful from within editing sessions to include from the current keg without leaving the terminal editor.

func (Dex) ByID

func (e Dex) ByID() Dex

ByID orders the Dex from lowest to highest node ID integer.

func (Dex) Highest

func (d Dex) Highest() int

Highest returns the highest integer value identifier.

func (Dex) HighestString

func (d Dex) HighestString() string

Highest returns Highest as string.

func (Dex) HighestWidth

func (d Dex) HighestWidth() int

HighestWidth returns width of highest integer identifier.

func (Dex) MD

func (e Dex) MD() string

MD renders the entire Dex as a Markdown list suitable for the standard dex/latest.md file.

func (*Dex) MarshalJSON

func (d *Dex) MarshalJSON() ([]byte, error)

MarshalJSON produces JSON text that contains one DexEntry per line that has not been HTML escaped (unlike the default).

func (Dex) Pretty

func (d Dex) Pretty() string

Pretty returns a string with pretty color string with time stamps rendered in more readable way.

func (Dex) PrettyLines

func (d Dex) PrettyLines() []string

PrettyLines returns Pretty but each line separate and without line return.

func (Dex) String

func (e Dex) String() string

String fulfills the fmt.Stringer interface as JSON. Any error returns a "null" string.

func (Dex) TSV

func (e Dex) TSV() string

TSV renders the entire Dex as a loadable tab-separated values file.

func (Dex) WithTitleText

func (e Dex) WithTitleText(keyword string) Dex

WithTitleText filters all nodes with titles that do not contain the text substring in the title.

type DexEntry

type DexEntry struct {
	U time.Time // updated
	T string    // title
	N int       // node id (also see ID)
}

DexEntry represents a single line in an index (usually the latest.md or nodes.tsv file). All three fields are always required.

func Last

func Last(kegpath string) *DexEntry

Last parses and returns a DexEntry of the most recently updated node from first line of the dex/latest.md file. If cannot determine returns nil.

func (DexEntry) AsInclude

func (e DexEntry) AsInclude() string

Asinclude returns a KEGML include link list item without the time suitable for creating include blocks in node files.

func (DexEntry) ID

func (e DexEntry) ID() string

ID returns the node identifier as a string instead of an integer. Returns an empty string if unable to parse the integer.

func (DexEntry) MD

func (e DexEntry) MD() string

MD returns the entry as a single Markdown list item for inclusion in the dex/nodex.md file:

  1. Second last changed in UTC in ISO8601 (RFC3339)
  2. Current title (always first line of README.md)
  3. Unique node integer identifier

Note that the second of last change is based on *any* file within the node directory changing, not just the README.md or meta files.

func (*DexEntry) MarshalJSON

func (e *DexEntry) MarshalJSON() ([]byte, error)

MarshalJSON produces JSON text that contains one DexEntry per line that has not been HTML escaped (unlike the default) and that uses a consistent DateTime format. Note that the (broken) encoding/json encoder is not used at all.

func (DexEntry) String

func (e DexEntry) String() string

String implements fmt.Stringer interface as MD.

func (DexEntry) TSV

func (e DexEntry) TSV() string

type Local

type Local struct {
	Name string
	Path string
}

Local contains a name to full path mapping for kegs stored locally.

Directories

Path Synopsis
cmd
keg
kn

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL