refactor(commands): separate commands and its core into two folders (#32)
- I think it would be better if one for commands only, one for the spec handling core logic so people won't be confused by the core logic inside the commands folder (cleaner I guess) - Regen docs
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "broot",
|
||||
Description: "Show the last modified date of files and directories",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--dates", Description: "Show the last modified date of files and directories"},
|
||||
{Name: "--no-dates", Description: "Don't show the last modified date"},
|
||||
{Name: "--only-folders", Description: "Only show folders"},
|
||||
|
||||
+4
-4
@@ -3,17 +3,17 @@ package fs
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "cd",
|
||||
Description: "change directory",
|
||||
MaxArgs: 0,
|
||||
Generator: func(tokens []string, prefix string, partial string) []core.Suggestion {
|
||||
Generator: func(tokens []string, prefix string, partial string) []spec.Suggestion {
|
||||
fullQuery := strings.Join(tokens[1:], " ")
|
||||
return core.FileGenerator("/")(tokens, prefix, fullQuery)
|
||||
return spec.FileGenerator("/")(tokens, prefix, fullQuery)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,16 +1,16 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "chmod",
|
||||
Description: "change file permissions",
|
||||
MaxArgs: 2, // 1 option + 1 file
|
||||
Subcommands: []core.Subcommand{},
|
||||
Options: []core.Option{
|
||||
Subcommands: []spec.Subcommand{},
|
||||
Options: []spec.Option{
|
||||
{Name: "-R", Description: "apply recursively to directories"},
|
||||
{Name: "--recursive", Description: "apply recursively to directories"},
|
||||
{Name: "-v", Description: "verbose: show each file processed"},
|
||||
@@ -31,8 +31,8 @@ func init() {
|
||||
|
||||
// modeGenerator suggests common chmod mode strings as the first argument,
|
||||
// then falls back to file suggestions for subsequent arguments
|
||||
func modeGenerator() core.GeneratorFunc {
|
||||
filegen := core.FileGenerator(".sh", ".py", ".bin", ".run")
|
||||
func modeGenerator() spec.GeneratorFunc {
|
||||
filegen := spec.FileGenerator(".sh", ".py", ".bin", ".run")
|
||||
|
||||
commonModes := []struct {
|
||||
mode string
|
||||
@@ -63,7 +63,7 @@ func modeGenerator() core.GeneratorFunc {
|
||||
{"664", "rw-rw-r-- (group can read+write)"},
|
||||
}
|
||||
|
||||
return func(tokens []string, prefix string, partial string) []core.Suggestion {
|
||||
return func(tokens []string, prefix string, partial string) []spec.Suggestion {
|
||||
argCount := 0
|
||||
for i := 1; i < len(tokens); i++ {
|
||||
t := tokens[i]
|
||||
@@ -73,10 +73,10 @@ func modeGenerator() core.GeneratorFunc {
|
||||
}
|
||||
|
||||
if argCount == 0 {
|
||||
var results []core.Suggestion
|
||||
var results []spec.Suggestion
|
||||
for _, m := range commonModes {
|
||||
if partial == "" || core.HasPrefixCI(m.mode, partial) {
|
||||
results = append(results, core.Suggestion{
|
||||
if partial == "" || spec.HasPrefixCI(m.mode, partial) {
|
||||
results = append(results, spec.Suggestion{
|
||||
Cmd: m.mode,
|
||||
Desc: m.desc,
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "chown",
|
||||
Description: "change file owner",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-R", Description: "recursive"},
|
||||
},
|
||||
})
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "cp",
|
||||
Description: "copy files and directories",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-r", Description: "recursive"},
|
||||
{Name: "-a", Description: "archive mode"},
|
||||
{Name: "-v", Description: "verbose"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "df",
|
||||
Description: "Display free disk space",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-a", Description: "Show all mount points"},
|
||||
{Name: "-b", Description: "Use 512-byte blocks (default)"},
|
||||
{Name: "-g", Description: "Use 1073741824-byte (1-Gbyte) blocks"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "dust",
|
||||
Description: "Like du but more intuitive",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--help", Description: "Show help for dust"},
|
||||
{Name: "--version", Description: "Print version information"},
|
||||
{Name: "--no-percent-bars", Description: "No percent bars or percentages will be displayed"},
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "exa",
|
||||
Description: "A modern replacement for ls",
|
||||
})
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "eza",
|
||||
Description: "A modern replacement for ls",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-?", Description: "Show list of command-line options"},
|
||||
{Name: "-v", Description: "Show version of eza"},
|
||||
{Name: "-1", Description: "Display one entry per line"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "find",
|
||||
Description: "Walk a file hierarchy",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-E", Description: "Permit find to be safely used in conjunction with xargs"},
|
||||
{Name: "-d", Description: "Cause find to perform a depth-first traversal"},
|
||||
{Name: "-f", Description: "Specify a file hierarch for find to traverse"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "fold",
|
||||
Description: "Fold long lines for finite width output device",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-b", Description: "File(s) to fold"},
|
||||
},
|
||||
})
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "ln",
|
||||
Description: "create links",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-s", Description: "symbolic link"},
|
||||
{Name: "-f", Description: "force"},
|
||||
},
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "ls",
|
||||
Description: "list directory contents",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-a", Description: "all files"},
|
||||
{Name: "-l", Description: "long format"},
|
||||
{Name: "-h", Description: "human readable"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "lsd",
|
||||
Description: "An ls command with a lot of pretty colors and some other stuff",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-1", Description: "Display one entry per line"},
|
||||
{Name: "-A", Description: "Do not list implied . and"},
|
||||
{Name: "-a", Description: "Do not ignore entries starting with"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "mkdir",
|
||||
Description: "make directories",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-p", Description: "create parent dirs"},
|
||||
{Name: "-v", Description: "verbose"},
|
||||
},
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "mv",
|
||||
Description: "move (rename) files",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-i", Description: "interactive"},
|
||||
{Name: "-f", Description: "force (overwrite)"},
|
||||
{Name: "-n", Description: "no clobber (don't overwrite)"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "paper",
|
||||
Description: "The Paper CLI",
|
||||
Subcommands: []core.Subcommand{
|
||||
Subcommands: []spec.Subcommand{
|
||||
{Name: "bench", Description: "Benchmark a Paper query"},
|
||||
{Name: "build", Description: "Build an Paper bundle"},
|
||||
{Name: "check", Description: "Check Paper source files"},
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
{Name: "version", Description: "Print the version of Paper"},
|
||||
{Name: "help", Description: "Help about any command"},
|
||||
},
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--benchmem", Description: "Report memory allocations with benchmark results"},
|
||||
{Name: "--bundle", Description: "Set bundle file(s) or directory path(s). This flag can be repeated"},
|
||||
{Name: "--count", Description: "Number of times to repeat each benchmark"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "rclone",
|
||||
Description: "Only list directories",
|
||||
Subcommands: []core.Subcommand{
|
||||
Subcommands: []spec.Subcommand{
|
||||
{Name: "about", Description: "Get quota information from the remote"},
|
||||
{Name: "authorize", Description: "Remote authorization"},
|
||||
{Name: "backend", Description: "Run a backend specific command"},
|
||||
@@ -60,7 +60,7 @@ func init() {
|
||||
{Name: "size", Description: "Prints the total size and number of objects in remote:path"},
|
||||
{Name: "sync", Description: "Make source and dest identical, modifying destination only"},
|
||||
},
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--dirs-only", Description: "Only list directories"},
|
||||
{Name: "--files-only", Description: "Only list files"},
|
||||
{Name: "--recursive", Description: "Recurse into the listing"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "readlink",
|
||||
Description: "Display file status",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-f", Description: "Do not force a newline to appear at the end of each piece of output"},
|
||||
},
|
||||
})
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "rm",
|
||||
Description: "remove files or directories",
|
||||
Generator: core.FileGenerator(),
|
||||
Options: []core.Option{
|
||||
Generator: spec.FileGenerator(),
|
||||
Options: []spec.Option{
|
||||
{Name: "-r", Description: "recursive"},
|
||||
{Name: "-f", Description: "force"},
|
||||
{Name: "-i", Description: "interactive"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "rmdir",
|
||||
Description: "Remove directories",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-p", Description: "Remove each directory of path"},
|
||||
},
|
||||
})
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "stow",
|
||||
Description: "Manage farms of symbolic links",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-n", Description: "Set the target directory to 'DIR' instead of the parent of the stow directory"},
|
||||
{Name: "-v", Description: "Ignore files ending in this Perl regex"},
|
||||
{Name: "--defer", Description: "Show Stow version, and exit"},
|
||||
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "tar",
|
||||
Description: "Use archive file or device ARCHIVE",
|
||||
Subcommands: []core.Subcommand{
|
||||
Subcommands: []spec.Subcommand{
|
||||
{Name: "A", Description: "Append archive to the end of another archive"},
|
||||
{Name: "c", Description: "Create a new archive"},
|
||||
{Name: "b", Description: "Set record size to BLOCKSx512 bytes"},
|
||||
@@ -41,7 +41,7 @@ func init() {
|
||||
{Name: "bad-dumpdir", Description: "\\"},
|
||||
{Name: "?", Description: "Display a short option summary and exit"},
|
||||
},
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "--force-local", Description: "Archive file is local even if it has a colon"},
|
||||
{Name: "--rmt-command", Description: "Use COMMAND instead of rmt when accessing remote archives"},
|
||||
{Name: "--rsh-command", Description: "Use COMMAND instead of rsh when accessing remote archives"},
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "touch",
|
||||
Description: "create or update file timestamp",
|
||||
Generator: core.FileGenerator(),
|
||||
Generator: spec.FileGenerator(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "trash",
|
||||
Description: "Trash, move files/folders to the trash",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-v", Description: "Print verbose output while moving items"},
|
||||
{Name: "-F", Description: "Use the Finder API to move items to the trash"},
|
||||
{Name: "-l", Description: "List items in the trash"},
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "tree",
|
||||
Description: "Display directories as trees (with optional color/HTML output)",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-a", Description: "All files are listed"},
|
||||
{Name: "-d", Description: "List directories only"},
|
||||
{Name: "-l", Description: "Follow symbolic links like directories"},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "unzip",
|
||||
Description: "Extract compressed files in a ZIP archive",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-l", Description: "List the contents of a zip file without extracting"},
|
||||
},
|
||||
})
|
||||
|
||||
+3
-3
@@ -1,14 +1,14 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "zip",
|
||||
Description: "Package and compress (archive) files into zip file",
|
||||
Options: []core.Option{
|
||||
Options: []spec.Option{
|
||||
{Name: "-r", Description: "Package and compress a directory and its contents, recursively"},
|
||||
{Name: "-e", Description: "Archive a directory and its contents with the highest level [9] of compression"},
|
||||
},
|
||||
|
||||
+10
-10
@@ -12,17 +12,17 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/versenilvis/fuzzy"
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func init() {
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "z",
|
||||
Description: "jump to directory",
|
||||
MaxArgs: 0,
|
||||
Generator: ZoxideGenerator(),
|
||||
})
|
||||
core.Register(&core.Spec{
|
||||
spec.Register(&spec.Spec{
|
||||
Name: "zi",
|
||||
Description: "jump to directory interactively",
|
||||
MaxArgs: 0,
|
||||
@@ -30,12 +30,12 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func ZoxideGenerator() core.GeneratorFunc {
|
||||
return func(tokens []string, prefix string, partial string) []core.Suggestion {
|
||||
func ZoxideGenerator() spec.GeneratorFunc {
|
||||
return func(tokens []string, prefix string, partial string) []spec.Suggestion {
|
||||
fullQuery := strings.Join(tokens[1:], " ")
|
||||
localSuggestions := core.FileGenerator("/")(tokens, prefix, fullQuery)
|
||||
localSuggestions := spec.FileGenerator("/")(tokens, prefix, fullQuery)
|
||||
|
||||
var zoxideSuggestions []core.Suggestion
|
||||
var zoxideSuggestions []spec.Suggestion
|
||||
cmd := exec.CommandContext(context.Background(), "zoxide", "query", "-l")
|
||||
out, err := cmd.Output()
|
||||
if err == nil {
|
||||
@@ -55,7 +55,7 @@ func ZoxideGenerator() core.GeneratorFunc {
|
||||
for i := 0; i < limit; i++ {
|
||||
path := dirs[i]
|
||||
display := strings.Replace(path, home, "~", 1)
|
||||
zoxideSuggestions = append(zoxideSuggestions, core.Suggestion{
|
||||
zoxideSuggestions = append(zoxideSuggestions, spec.Suggestion{
|
||||
Cmd: path,
|
||||
Desc: display,
|
||||
})
|
||||
@@ -66,7 +66,7 @@ func ZoxideGenerator() core.GeneratorFunc {
|
||||
for _, m := range matches {
|
||||
path := m.Str
|
||||
display := strings.Replace(path, home, "~", 1)
|
||||
zoxideSuggestions = append(zoxideSuggestions, core.Suggestion{
|
||||
zoxideSuggestions = append(zoxideSuggestions, spec.Suggestion{
|
||||
Cmd: path,
|
||||
Desc: display,
|
||||
})
|
||||
@@ -74,7 +74,7 @@ func ZoxideGenerator() core.GeneratorFunc {
|
||||
}
|
||||
}
|
||||
|
||||
var finalResults []core.Suggestion
|
||||
var finalResults []spec.Suggestion
|
||||
seen := make(map[string]bool)
|
||||
|
||||
finalResults = append(finalResults, localSuggestions...)
|
||||
|
||||
Reference in New Issue
Block a user