diff --git a/cmd/grepturbo/main.go b/cmd/grepturbo/main.go index 3a5ef81..8e36281 100644 --- a/cmd/grepturbo/main.go +++ b/cmd/grepturbo/main.go @@ -14,6 +14,20 @@ import ( const defaultIndexDir = ".grepturbo" func main() { + // If the first arg isn't a known subcommand or flag, treat it as a search pattern + // so `grepturbo ` works alongside `grepturbo search `. + knownSubcmds := map[string]bool{"build": true, "search": true, "init": true, "help": true, "completion": true} + if len(os.Args) > 1 { + first := os.Args[1] + if first != "" && first[0] != '-' && !knownSubcmds[first] { + // Inject "search" before the pattern + newArgs := make([]string, 0, len(os.Args)+1) + newArgs = append(newArgs, os.Args[0], "search") + newArgs = append(newArgs, os.Args[1:]...) + os.Args = newArgs + } + } + rootCmd := &cobra.Command{ Use: "grepturbo", Short: "Index-accelerated regex search",