toolcmd

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ScopeAll = iota
	ScopeNamed
	ScopeHistory
)

Variables

View Source
var AutoJumpChdirCmd = &gcli.Command{
	Name:    "chdir",
	Aliases: []string{"into", "to"},
	Desc:    "add directory path to history, by the jump dir hooks.",
	Config: func(c *gcli.Command) {
		c.MustFromStruct(&ajcOpts, gflag.TagRuleSimple)
		c.AddArg("path", "The real directory path. if empty, use current workdir")
	},
	Func: func(c *gcli.Command, _ []string) error {
		path := c.Arg("path").String()
		if len(path) == 0 {
			return c.NewErrf("path is empty or invalid")
		}

		realPath, ok := app.QJump.AddHistory(path)
		if ok {
			app.L.Infof("jump to path %q success", realPath)
			if !ajcOpts.Quiet {
				colorp.Successf("Into %q\n", realPath)
			}
		} else {
			colorp.Warnf("Invalid path %q\n", realPath)
		}

		return nil
	},
}

AutoJumpChdirCmd command

View Source
var AutoJumpGetCmd = &gcli.Command{
	Name:    "get",
	Aliases: []string{"path"},
	Desc:    "Get the real directory path by given name.",
	Config: func(c *gcli.Command) {
		c.MustFromStruct(&ajgOpts, gflag.TagRuleSimple)
		c.AddArg("keywords", "The target directory name or path or keywords.\n Start with ^ for exclude", true, true)
	},
	Func: func(c *gcli.Command, _ []string) error {
		keywords := c.Arg("keywords").Strings()
		dirPath := app.QJump.CheckOrMatch(keywords)

		if !ajgOpts.Quiet && len(dirPath) == 0 {
			return c.NewErrf("not found path by keywords: %v", keywords)
		}

		app.L.Infof("input keywords: %v, match dirPath: %s", keywords, dirPath)
		stdio.WriteString(dirPath)
		return nil
	},
}

AutoJumpGetCmd command

View Source
var AutoJumpListCmd = &gcli.Command{
	Name:    "list",
	Aliases: []string{"ls"},
	Desc:    "list the jump storage data in local",
	Config: func(c *gcli.Command) {
		c.AddArg("type", "the jump info type name. allow: prev,last,history,all")
	},
	Func: func(c *gcli.Command, _ []string) error {
		colorp.Infof("Jump storage datafile: %s\n", app.QJump.Datafile())
		colorp.Greenln("Jump storage data in local:")

		dp := dump.NewWithOptions(dump.WithoutPosition(), dump.SkipPrivate())
		dp.Println(app.QJump.Metadata)
		show.MList(app.QJump.Metadata)
		return nil
	},
}

AutoJumpListCmd command

View Source
var AutoJumpMatchCmd = &gcli.Command{
	Name:    "search",
	Aliases: []string{"hint", "match"},
	Desc:    "Match directory paths by given keywords",
	Config: func(c *gcli.Command) {
		c.MustFromStruct(&ajmOpts, gflag.TagRuleSimple)
		c.AddArg("keywords", "The keywords to match, allow limit by multi", false, true)
	},
	Func: func(c *gcli.Command, _ []string) error {
		var results []string
		keywords := c.Arg("keywords").Strings()
		keywords = app.QJump.FormatKeywords(keywords)

		if ajmOpts.Scope == ScopeNamed {
			results = app.QJump.SearchNamed(keywords, ajmOpts.Limit, !ajmOpts.OnlyPath)
		} else if ajmOpts.Scope == ScopeHistory {
			results = app.QJump.SearchHistory(keywords, ajmOpts.Limit)
		} else {
			results = app.QJump.Search(keywords, ajmOpts.Limit, !ajmOpts.OnlyPath)
		}

		var sb strings.Builder
		matchNum := len(results)
		app.L.Infof("input search keywords %v, search results: %v", keywords, results)

		for i, dirPath := range results {
			sb.WriteString(dirPath)
			if matchNum != i+1 {
				sb.WriteByte('\n')
			}
		}

		stdio.WriteString(sb.String())
		return nil
	},
}

AutoJumpMatchCmd command

View Source
var AutoJumpSetCmd = &gcli.Command{
	Name:    "set",
	Aliases: []string{"add"},
	Desc:    "Set the name to real directory path mapping",
	Config: func(c *gcli.Command) {
		c.AddArg("name", "The name of the directory path", true)
		c.AddArg("path", "The real directory path", true)
	},
	Func: func(c *gcli.Command, _ []string) error {
		name := c.Arg("name").String()
		path := c.Arg("path").String()

		if app.QJump.AddNamed(name, path) {
			colorp.Successf("Set jump name %q to path %q\n", name, path)
		} else {
			colorp.Warnln("Set jump name %q to path %q failed", name, path)
		}

		return nil
	},
}

AutoJumpSetCmd command

View Source
var AutoJumpShellCmd = &gcli.Command{
	Name:    "shell",
	Aliases: []string{"active", "script"},
	Desc:    "Generate shell script for give shell env name.",
	Help: `
  Enable quick jump for bash(add to <mga>~/.bashrc</>):
    # shell func is: jump
    <mga>eval "$(kite tool jump shell bash)"</>

Enable quick jump for zsh(add to <mga>~/.zshrc</>):
    # shell func is: jump
    <mga>eval "$(kite tool jump shell zsh)"</>
    # set the bind func name is: j
    <mga>eval "$(kite tool jump shell --bind j zsh)"</>

Enable quick jump for pwsh(add to <mga>$PROFILE</>):
    # jump func is: j
    <mga>kite tool jump shell --bind j pwsh | Out-String | Invoke-Expression</>

`,
	Config: func(c *gcli.Command) {
		c.MustFromStruct(&jsOpts, gflag.TagRuleSimple)
		c.AddArg("shell", "The shell name. allows: bash, zsh, fish, pwsh.")
	},
	Func: func(c *gcli.Command, _ []string) error {
		shellName := c.Arg("shell").String()
		if shellName == "" {
			shellName = sysutil.CurrentShell(true)
		}

		if !quickjump.IsSupported(shellName) {
			colorp.Redf("The shell %q is not supported yet!\n", shellName)
			return nil
		}

		script, err := quickjump.GenScript(shellName, jsOpts.Bind)
		if err != nil {
			return err
		}

		stdio.WriteString(script)
		return nil
	},
}

AutoJumpShellCmd command

View Source
var DateCmd = &gcli.Command{
	Name:    "date",
	Aliases: []string{"dt", "time"},
	Desc:    "display or parse the date and time",
	Subs: []*gcli.Command{
		DatePrintCmd,
	},
}

DateCmd command

View Source
var DatePrintCmd = &gcli.Command{
	Name: "print",
	Desc: "print the current date and time",
	Config: func(c *gcli.Command) {
		c.MustFromStruct(&dateParseOpts)
	},
	Func: func(c *gcli.Command, _ []string) error {
		tx := timex.Now()

		s := tx.DateFormat(dateParseOpts.Format)
		if dateParseOpts.Inline {
			fmt.Print(s, " ", tx.Unix())
		} else {
			fmt.Println(s, tx.Unix())
		}
		return nil
	},
}

DatePrintCmd command

View Source
var MathCalcCmd = &gcli.Command{
	Name:    "math",
	Aliases: []string{"calc"},
	Desc:    "list the jump storage data in local",
	Config: func(c *gcli.Command) {

	},
	Func: func(c *gcli.Command, _ []string) error {
		return errorx.New("TODO")
	},
}

MathCalcCmd command

View Source
var QuickJumpCleanCmd = &gcli.Command{
	Name:    "clean",
	Aliases: []string{"clear"},
	Desc:    "clean invalid directory paths from history",
	Config: func(c *gcli.Command) {
		c.AddArg("path", "The history directory path. if empty, clean all invalid dirs")
	},
	Func: func(c *gcli.Command, args []string) error {
		ss := app.QJump.CleanHistories()

		if len(ss) > 0 {
			show.AList("Cleaned invalid paths", ss)
		} else {
			colorp.Infoln("No invalid paths to clean")
		}
		return nil
	},
}

QuickJumpCleanCmd command

View Source
var QuickJumpCmd = &gcli.Command{
	Name:    "jump",
	Aliases: []string{"goto"},
	Desc:    "Jump helps you navigate faster by your history.",
	Subs: []*gcli.Command{
		AutoJumpListCmd,
		AutoJumpShellCmd,
		AutoJumpMatchCmd,
		AutoJumpGetCmd,
		AutoJumpSetCmd,
		AutoJumpChdirCmd,
		QuickJumpCleanCmd,
	},
	Config: func(c *gcli.Command) {

	},
}

QuickJumpCmd command

View Source
var RunAnyCmd = &gcli.Command{
	Name:    "run",
	Desc:    "Run any aliases, script task/file/apps, plugins and system commands",
	Aliases: []string{"exec"},
	Config: func(c *gcli.Command) {
		runOpts.BindCommonFlags2(c)
		runOpts.wrapType.SetEnum(kscript.AllowTypes)
		runOpts.runType.SetEnum([]string{"alias", "script", "ext", "plugin", "system"})

		c.BoolOpt2(&runOpts.global, "global, g", "Show global script tasks (loaded from DefineFiles config)")
		c.BoolOpt2(&runOpts.listAll, "list, l", "List information for all scripts or one script")
		c.BoolOpt2(&runOpts.showInfo, "show, info, i", "Show information for input alias/script/plugin name")
		c.BoolOpt2(&runOpts.search, "search, s", "Display all matched scripts by the input name")
		c.BoolOpt2(&runOpts.verbose, "verbose, verb", "Display context information on execute")

		c.StrOpt2(&runOpts.chdir, "chdir, cd", "auto find match dir and chdir as workdir")
		c.VarOpt2(&runOpts.envMap, "env,e", "custom set ENV value on run command, format: `KEY=VALUE`")
		c.VarOpt2(&runOpts.varMap, "vars,var", "custom set var value on run command, format: `name=value`")
		c.VarOpt(&runOpts.runType, "type", "t", "direct set type for run input, allow: "+runOpts.runType.EnumString())
		c.VarOpt(&runOpts.wrapType, "shell", "", "wrap shell type for run input script, allow: "+runOpts.wrapType.EnumString())

		c.AddArg("command", "The command for execute, can be with custom arguments")
	},
	Func: runAnything,
	Help: `
## System command

$ kite run ls -al

## Run script task

$ kite run --var key0=value0 --var key1=value1 task_name [args ... for task]

## Custom scripts

> default in the $config/scripts.yml or dir: $base/scripts

Can use '$@' '$*' ${ENV_KEY} ${name} ${top.name} at script. will auto replace to input arguments
<info>Examples</>:

  # scripts.yml
  st: git status
  co: git checkout $@
  br: git branch $*
`,
}

RunAnyCmd instance

View Source
var ShellCmd = &gcli.Command{
	Name:    "shell",
	Aliases: []string{"sh"},
	Desc:    "Listen, record, query user executed shell command",
	Subs: []*gcli.Command{
		ShellListenCmd,
	},
	Config: func(c *gcli.Command) {

	},
}

ShellCmd os shell tool command

View Source
var ShellListenCmd = &gcli.Command{
	Name:    "listen",
	Aliases: []string{"watch"},
	Desc:    "Listen user executed shell command",
	Config: func(c *gcli.Command) {

	},
	Func: func(c *gcli.Command, args []string) error {
		return nil
	},
}

ShellListenCmd listen user executed command

ToolsCmd command

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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