-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1893 from rsteube/add-zoxide
added zoxide
- Loading branch information
Showing
10 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
} |