utils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(bin string, args []string) (string, error)

Exec a command

func GetCmdStr

func GetCmdStr(bin string, args []string) string

GetCmdStr returns the string of a command

func GetMdLinkHash

func GetMdLinkHash(link string) string

GetMdLinkHash encodes s to insert into an MD link.

func GetPrelude

func GetPrelude(s string) (string, map[string]interface{}, error)

GetPrelude decodes and remove the prelude from the input string.

func LineIndex

func LineIndex(content string, search string) int

LineIndex returns line index of search in content.

func LineLess

func LineLess(P int, f func(*MdTitleTree)) func(*MdTitleTree)

LineLess select titles of Line<P

func PowerLess

func PowerLess(P int, f func(*MdTitleTree)) func(*MdTitleTree)

PowerLess select titles of Power<P

func Shell

func Shell(wd, s string) (string, error)

Shell exec a string.

Types

type CliError

type CliError struct {
	Err error
	Cmd string
}

CliError is an error of cli command

func (*CliError) Error

func (c *CliError) Error() string

type MdTitle

type MdTitle struct {
	Line      int
	Power     int
	Duplicate int
	Title     string
}

MdTitle is a markdwon title.

func GetAllMdTitles

func GetAllMdTitles(content string) []MdTitle

GetAllMdTitles extracts all MD titles markup.

type MdTitleTree

type MdTitleTree struct {
	MdTitle
	Parent *MdTitleTree
	Items  []*MdTitleTree
}

MdTitleTree is an MdTitle with tree capabilities

func MakeTitleTree

func MakeTitleTree(titles []MdTitle) *MdTitleTree

MakeTitleTree transform a raw list of titles into a tree.

func (*MdTitleTree) String

func (m *MdTitleTree) String() string

func (*MdTitleTree) Traverse

func (m *MdTitleTree) Traverse(f func(*MdTitleTree))

Traverse a tree

type TempCmd

type TempCmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

TempCmd ...

func Command

func Command(cwd string, cmd string) (*TempCmd, error)

Command Return a new exec.Cmd object for the given command string

func NewTempCmd

func NewTempCmd(cwd string, cmd string) (*TempCmd, error)

NewTempCmd is a cmd wrapped into a tmp file

func (*TempCmd) Run

func (t *TempCmd) Run() error

Run the cmd

func (*TempCmd) Wait

func (t *TempCmd) Wait() error

Wait wait for command then delete the tmp file.

Jump to

Keyboard shortcuts

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