Genivia / ugrep

NEW ugrep 6.5: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.57k stars 109 forks source link

Suggestions #333

Closed pikumar closed 8 months ago

pikumar commented 8 months ago
  1. Please consider supporting "py" along with "Python" Instead of saying ug -tPython PATTERN, I would like to say "ug -tpy PATTERN"

  2. Could I say ug PATTERN *.py and ug knows that I want to recursively only look at python files. (Maybe it conflicts with how others use it - I don't know)

Thanks for ug!

genivia-inc commented 8 months ago

Thank you for your suggestion and feedback.

I've recently added bash, fish and zsh autocompletions #198 which will complete the type names for you. So typing -tPy TAB should work to complete to -tPython. The repo download has them. I will release an update that includes the new bash, fish and zsh completions soon.

Note that type Python matches both the filename suffix .py and also Python "magic bytes", versus python that only matches the file name suffix .py.

If you just want to just match filename suffix(es), then -Opy is the simplest option to use.

Hope this helps.

genivia-inc commented 8 months ago

One additional possibility is to let -t (--file-type) also accept a filename extension that is listed under -t list, then use this extension as an alias for the full lower-case type name. So -t py is an alias for -t python (but not for -t Python perhaps?) There is a slight possibility of two types sharing the same filename extension, making this choice ambiguous. Ambiguous cases should be rejected as aliases. For example, -t h is ambiguous for C or C++ header file.

genivia-inc commented 8 months ago

The updated -t option shortcut with filename extensions like -tpy is included in release v4.4.0.

genivia-inc commented 8 months ago

One more quick thought on this. Perhaps we can also allow a type prefix to match, like -tPy will be a shorthand for -tPython. This would only be valid if the specified prefix is unambiguous. So for example-tp is not valid, since several types start with p, but -tc is valid, because it specifies a full type name c and also -tpy is valid because only one type name starts with py. We can still also associate filename extensions with type names, as we just did for v4.4, as a last resort to find a suitable type. This would be the most flexible and "smart" approach. I have played with this and I don't see a downside to this, since types will not change in the future and very few, if any, additional types can be expected. Nevertheless, for scripting I recommend using the full type name to avoid any potential ambiguous type name prefix conflicts in the long run (who knows?).