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

Bash autocompletion #327

Closed jack6th closed 9 months ago

jack6th commented 9 months ago

ugrep is good tool and it has so many command line options.
Is there a bash auto completion script available?

genivia-inc commented 9 months ago

Thank you for your suggestion.

Bash autocompletion sounds a great idea.

genivia-inc commented 9 months ago

I've written a ugrep bash completion script.

The completion script is located in the ugrep repo completions directory. Please check it out.

I had to jump through some hoops to get long option completion to work properly, e.g. with = arguments completed. No space is allowed after = with ugrep options, so no space is generated by the bash completion. Nevertheless, I will also allow a space after = in the upcoming ugrep release to make it a bit easier to work with long options.

The completion script checks if _init_completion is defined, which should be with bash 4. If not, it exits. This is to avoid issues with older bash e.g. on MacOS.

PS. I'm also updating configure and make install to install bash completions for the ugrep commands.

PPS. For a "usage" overview, instead of 4 examples, perhaps a list of options with one-line descriptions would be better? Feel free to suggest/recommend.

genivia-inc commented 9 months ago

See also #198 for progress on fish and zsh completion.

genivia-inc commented 9 months ago

Completed and included in the latest commit. Will be released as an official release in the next release cycle.

This update performs bash completions for the ug, ug+, ugrep, and ugrep+ commands. It also suggests option argument values for -t (--file-type=), --encoding=, -D (--devices=), -d (--directories=), --hexdump=, --sort=, and -Z (--fuzzy=). Note that the = is mandatory with long option argument values.