Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added zoxide #1893

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions completers/zoxide_completer/cmd/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add <PATHS>...",
Short: "Add a new directory or increment its rank",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(addCmd).Standalone()

addCmd.Flags().BoolP("help", "h", false, "Print help")
addCmd.Flags().BoolP("version", "V", false, "Print version")
rootCmd.AddCommand(addCmd)

carapace.Gen(addCmd).PositionalAnyCompletion(
carapace.ActionDirectories(),
)
}
20 changes: 20 additions & 0 deletions completers/zoxide_completer/cmd/edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var editCmd = &cobra.Command{
Use: "edit",
Short: "Edit the database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(editCmd).Standalone()

editCmd.Flags().BoolP("help", "h", false, "Print help")
editCmd.Flags().BoolP("version", "V", false, "Print version")
rootCmd.AddCommand(editCmd)
}
31 changes: 31 additions & 0 deletions completers/zoxide_completer/cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var importCmd = &cobra.Command{
Use: "import [OPTIONS] --from <FROM> <PATH>",
Short: "Import entries from another application",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(importCmd).Standalone()

importCmd.Flags().String("from", "", "Application to import from")
importCmd.Flags().BoolP("help", "h", false, "Print help")
importCmd.Flags().Bool("merge", false, "Merge into existing database")
importCmd.Flags().BoolP("version", "V", false, "Print version")
importCmd.MarkFlagRequired("from")
rootCmd.AddCommand(importCmd)

carapace.Gen(importCmd).FlagCompletion(carapace.ActionMap{
"from": carapace.ActionValues("autojump", "z"),
})

carapace.Gen(importCmd).PositionalCompletion(
carapace.ActionFiles(),
)
}
35 changes: 35 additions & 0 deletions completers/zoxide_completer/cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var initCmd = &cobra.Command{
Use: "init [OPTIONS] <SHELL",
Short: "Generate shell configuration",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(initCmd).Standalone()

initCmd.Flags().String("cmd", "", "Changes the prefix of the `z` and `zi` commands")
initCmd.Flags().BoolP("help", "h", false, "Print help")
initCmd.Flags().String("hook", "", "Changes how often zoxide increments a directory's score")
initCmd.Flags().Bool("no-cmd", false, "Prevents zoxide from defining the `z` and `zi` commands")
initCmd.Flags().BoolP("version", "V", false, "Print version")
rootCmd.AddCommand(initCmd)

carapace.Gen(initCmd).FlagCompletion(carapace.ActionMap{
"hook": carapace.ActionValuesDescribed(
"none", "Never",
"prompt", "At every shell prompt",
"pwd", "Whenever the directory is changed",
),
})

carapace.Gen(initCmd).PositionalCompletion(
carapace.ActionValues("ash", "elvish", "fish", "nushell", "posix", "powershell", "xonsh", "zsh"),
)
}
29 changes: 29 additions & 0 deletions completers/zoxide_completer/cmd/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var queryCmd = &cobra.Command{
Use: "query [KEYWORDS]...",
Short: "Search for a directory in the database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(queryCmd).Standalone()

queryCmd.Flags().BoolP("all", "a", false, "Show unavailable directories")
queryCmd.Flags().String("exclude", "", "Exclude the current directory")
queryCmd.Flags().BoolP("help", "h", false, "Print help")
queryCmd.Flags().BoolP("interactive", "i", false, "Use interactive selection")
queryCmd.Flags().BoolP("list", "l", false, "List all matching directories")
queryCmd.Flags().BoolP("score", "s", false, "Print score with results")
queryCmd.Flags().BoolP("version", "V", false, "Print version")
rootCmd.AddCommand(queryCmd)

carapace.Gen(queryCmd).FlagCompletion(carapace.ActionMap{
"exclude": carapace.ActionDirectories(),
})
}
20 changes: 20 additions & 0 deletions completers/zoxide_completer/cmd/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var removeCmd = &cobra.Command{
Use: "remove [PATHS]...",
Short: "Remove a directory from the database",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(removeCmd).Standalone()

removeCmd.Flags().BoolP("help", "h", false, "Print help")
removeCmd.Flags().BoolP("version", "V", false, "Print version")
rootCmd.AddCommand(removeCmd)
}
24 changes: 24 additions & 0 deletions completers/zoxide_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "zoxide",
Short: "A smarter cd command for your terminal",
Long: "https://github.com/ajeetdsouza/zoxide",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolP("help", "h", false, "Print help")
rootCmd.Flags().BoolP("version", "V", false, "Print version")
}
7 changes: 7 additions & 0 deletions completers/zoxide_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/zoxide_completer/cmd"

func main() {
cmd.Execute()
}
33 changes: 33 additions & 0 deletions pkg/actions/env/zoxide.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package env

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/conditions"
"github.com/rsteube/carapace-bridge/pkg/actions/bridge"
"github.com/rsteube/carapace/pkg/style"
)

func init() {
knownVariables["zoxide"] = func() variables {
_bool := carapace.ActionValuesDescribed("0", "disabled", "1", "enabled").StyleF(style.ForKeyword)
return variables{
Condition: conditions.ConditionPath("zoxide"),
Variables: map[string]string{
"_ZO_DATA_DIR": "Path for zoxide data files",
"_ZO_ECHO": "Print the matched directory before navigating to it when set to 1",
"_ZO_EXCLUDE_DIRS": "List of directory globs to be excluded",
"_ZO_FZF_OPTS": "Custom flags to pass to fzf",
"_ZO_MAXAGE": "Maximum total age after which entries start getting deleted",
"_ZO_RESOLVE_SYMLINKS": "Resolve symlinks when storing paths",
},
VariableCompletion: map[string]carapace.Action{
"_ZO_DATA_DIR": carapace.ActionDirectories(),
"_ZO_ECHO": _bool,
"_ZO_EXCLUDE_DIRS": carapace.ActionDirectories().List(","), // TODO verify
"_ZO_FZF_OPTS": bridge.ActionCarapaceBin("fzf").Split(),
"_ZO_MAXAGE": carapace.ActionValues(),
"_ZO_RESOLVE_SYMLINKS": _bool,
},
}
}
}
24 changes: 24 additions & 0 deletions pkg/actions/tools/zoxide/zoxide.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package zoxide

import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

// ActionDirectories completes zoxide directories
//
// /tmp/
// /tmp/dirA/
func ActionDirectories() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("zoxide", "query", "--list", c.Value)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
for index := range lines {
lines[index] += "/"
}
return carapace.ActionValues(lines[:len(lines)-1]...).MultiParts("/").StyleF(style.ForPathExt)
})
})
}