Skip to content

Commit

Permalink
Merge pull request #86 from rsteube/add-grep
Browse files Browse the repository at this point in the history
added grep
  • Loading branch information
rsteube authored Sep 1, 2020
2 parents 25c4042 + a755a1c commit ed7f2c9
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
4 changes: 4 additions & 0 deletions carapace/cmd/completers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
fold "github.com/rsteube/carapace-bin/completers/fold_completer/cmd"
git "github.com/rsteube/carapace-bin/completers/git_completer/cmd"
gradle "github.com/rsteube/carapace-bin/completers/gradle_completer/cmd"
grep "github.com/rsteube/carapace-bin/completers/grep_completer/cmd"
head "github.com/rsteube/carapace-bin/completers/head_completer/cmd"
hostid "github.com/rsteube/carapace-bin/completers/hostid_completer/cmd"
id "github.com/rsteube/carapace-bin/completers/id_completer/cmd"
Expand Down Expand Up @@ -117,6 +118,7 @@ var completers = []string{
"fold",
"git",
"gradle",
"grep",
"head",
"hostid",
"id",
Expand Down Expand Up @@ -234,6 +236,8 @@ func executeCompleter(completer string) {
git.Execute()
case "gradle":
gradle.Execute()
case "grep":
grep.Execute()
case "head":
head.Execute()
case "hostid":
Expand Down
90 changes: 90 additions & 0 deletions completers/grep_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cmd

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

var rootCmd = &cobra.Command{
Use: "grep",
Short: "",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolS("I", "I", false, "equivalent to --binary-files=without-match")
//rootCmd.Flags().BoolS("NUM", "NUM", false, "same as --context=NUM")
rootCmd.Flags().StringP("after-context", "A", "", "print NUM lines of trailing context")
rootCmd.Flags().BoolP("basic-regexp", "G", false, "PATTERNS are basic regular expressions")
rootCmd.Flags().StringP("before-context", "B", "", "print NUM lines of leading context")
rootCmd.Flags().BoolP("binary", "U", false, "do not strip CR characters at EOL (MSDOS/Windows)")
rootCmd.Flags().String("binary-files", "", "assume that binary files are TYPE;")
rootCmd.Flags().BoolP("byte-offset", "b", false, "print the byte offset with output lines")
rootCmd.Flags().String("color", "", "")
rootCmd.Flags().String("colour", "", "use markers to highlight the matching strings;")
rootCmd.Flags().StringP("context", "C", "", "print NUM lines of output context")
rootCmd.Flags().BoolP("count", "c", false, "print only a count of selected lines per FILE")
rootCmd.Flags().BoolP("dereference-recursive", "R", false, "likewise, but follow all symlinks")
rootCmd.Flags().StringP("devices", "D", "", "how to handle devices, FIFOs and sockets;")
rootCmd.Flags().StringP("directories", "d", "", "how to handle directories;")
rootCmd.Flags().String("exclude", "", "skip files that match GLOB")
rootCmd.Flags().String("exclude-dir", "", "skip directories that match GLOB")
rootCmd.Flags().String("exclude-from", "", "skip files that match any file pattern from FILE")
rootCmd.Flags().BoolP("extended-regexp", "E", false, "PATTERNS are extended regular expressions")
rootCmd.Flags().StringP("file", "f", "", "take PATTERNS from FILE")
rootCmd.Flags().BoolP("files-with-matches", "l", false, "print only names of FILEs with selected lines")
rootCmd.Flags().BoolP("files-without-match", "L", false, "print only names of FILEs with no selected lines")
rootCmd.Flags().BoolP("fixed-strings", "F", false, "PATTERNS are strings")
rootCmd.Flags().Bool("help", false, "display this help text and exit")
rootCmd.Flags().BoolP("ignore-case", "i", false, "ignore case distinctions in patterns and data")
rootCmd.Flags().String("include", "", "search only files that match GLOB (a file pattern)")
rootCmd.Flags().BoolP("initial-tab", "T", false, "make tabs line up (if needed)")
rootCmd.Flags().BoolP("invert-match", "v", false, "select non-matching lines")
rootCmd.Flags().String("label", "", "use LABEL as the standard input file name prefix")
rootCmd.Flags().Bool("line-buffered", false, "flush output on every line")
rootCmd.Flags().BoolP("line-number", "n", false, "print line number with output lines")
rootCmd.Flags().BoolP("line-regexp", "x", false, "match only whole lines")
rootCmd.Flags().StringP("max-count", "m", "", "stop after NUM selected lines")
rootCmd.Flags().BoolP("no-filename", "h", false, "suppress the file name prefix on output")
rootCmd.Flags().Bool("no-ignore-case", false, "do not ignore case distinctions (default)")
rootCmd.Flags().BoolP("no-messages", "s", false, "suppress error messages")
rootCmd.Flags().BoolP("null", "Z", false, "print 0 byte after FILE name")
rootCmd.Flags().BoolP("null-data", "z", false, "a data line ends in 0 byte, not newline")
rootCmd.Flags().BoolP("only-matching", "o", false, "show only nonempty parts of lines that match")
rootCmd.Flags().BoolP("perl-regexp", "P", false, "PATTERNS are Perl regular expressions")
rootCmd.Flags().BoolP("quiet", "q", false, "suppress all normal output")
rootCmd.Flags().Bool("silent", false, "suppress all normal output")
rootCmd.Flags().BoolP("recursive", "r", false, "like --directories=recurse")
rootCmd.Flags().StringP("regexp", "e", "", "use PATTERNS for matching")
rootCmd.Flags().BoolP("text", "a", false, "equivalent to --binary-files=text")
rootCmd.Flags().BoolP("version", "V", false, "display version information and exit")
rootCmd.Flags().BoolP("with-filename", "H", false, "print file name with output lines")
rootCmd.Flags().BoolP("word-regexp", "w", false, "match only whole words")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"file": carapace.ActionFiles(""),
"binary-files": carapace.ActionValues("binary", "test", "without-match"),
"directories": carapace.ActionValues("read", "recurse", "skip"),
"devices": carapace.ActionValues("read", "skip"),
"exclude-from": carapace.ActionFiles(""),
"color": carapace.ActionValues("always", "never", "auto"),
"colour": carapace.ActionValues("always", "never", "auto"),
})

carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionCallback(func(args []string) carapace.Action {
if rootCmd.Flag("file").Changed {
return carapace.ActionFiles("")
} else {
return carapace.ActionValues()
}
}),
)

carapace.Gen(rootCmd).PositionalAnyCompletion(carapace.ActionFiles(""))
}
7 changes: 7 additions & 0 deletions completers/grep_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/grep_completer/cmd"

func main() {
cmd.Execute()
}
2 changes: 1 addition & 1 deletion completers/sed_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
rootCmd.Flags().Bool("follow-symlinks", false, "follow symlinks when processing in place")
rootCmd.Flags().Bool("help", false, "display this help and exit")
rootCmd.Flags().StringP("in-place", "i", "", "edit files in place (makes backup if SUFFIX supplied)")
rootCmd.Flags().StringP("line-length", "l", "", "specify the desired line-wrap length for the `l' command")
rootCmd.Flags().StringP("line-length", "l", "", "specify the desired line-wrap length for the l command")
rootCmd.Flags().BoolP("null-data", "z", false, "separate lines by NUL characters")
rootCmd.Flags().Bool("posix", false, "disable all GNU extensions")
rootCmd.Flags().StringP("quiet", "n", "", "suppress automatic printing of pattern space")
Expand Down

0 comments on commit ed7f2c9

Please sign in to comment.