feat(tui): Add Regex search support with toggle (Ctrl+g) - #337
Open
hongyi-zhao wants to merge 3 commits into
Open
feat(tui): Add Regex search support with toggle (Ctrl+g)#337hongyi-zhao wants to merge 3 commits into
hongyi-zhao wants to merge 3 commits into
Conversation
Closes ddworken#336 This PR introduces support for **Regex-based searching** in hishtory. It allows users to perform precise matching using regular expressions instead of the default fuzzy matching. It also integrates this feature into the TUI with a new toggle mode. - Added support for `regex:` and `re:` prefixes in search queries. - Implemented `extractRegexPatterns` to correctly parse regex patterns from the query string, preserving escape characters (e.g., `\.sh$`). - Implemented `filterByRegex` to filter history entries using Go's `regexp` package after fetching results from the database. - *Note: This approach avoids dependencies on SQLite CGO extensions for REGEXP support, ensuring compatibility.* - **New Mode**: Added a `regexMode` state to the TUI model. - **Visual Indicator**: When Regex mode is enabled, the prompt changes to `Search Query: [REGEX] >`. - **Automatic Prefixing**: When in Regex mode, the user's input is automatically treated as a regex pattern (internally wrapped with `re:`). - **Keybinding**: Added `Ctrl+g` (default) to toggle Regex mode on/off. - **Help Menu**: Updated both `ShortHelp` (footer) and `FullHelp` (Ctrl+h) to display the new keybinding. - **Layout**: Adjusted the `FullHelp` layout to include `ToggleRegex` in the second column for better visibility. 1. Rebuild and install: `go build . && ./hishtory install` 2. Open the TUI via `Ctrl+r`. 3. Press `Ctrl+g`. You should see the `[REGEX]` indicator appear. 4. Try regex queries: - `^git` (Commands starting with git) - `\.sh$` (Commands ending with .sh) - `docker.*run` 5. Press `Ctrl+h` to verify the keybinding `ctrl+g` is listed in the help menu. - [x] Logic for regex filtering - [x] TUI toggle implementation - [x] Keybinding configuration (`Ctrl+g`) - [x] Help menu updates
- Removed `m.regexMode` from the update condition in `runQueryAndUpdateTable` to prevent database re-queries on every keypress (e.g., Up/Down arrows). - Forced a table update (`forceUpdateTable=true`) only when toggling the regex mode via `Ctrl+g`. This fixes the issue where cursor navigation would reset the view and freeze scrolling while in Regex mode.
|
This doesn't cover |
…layout This PR introduces several improvements to the `query` subcommand: 1. **Manual Flag Parsing for `query` command**: Since `queryCmd` has `DisableFlagParsing: true`, the standard `--limit` flag was being ignored. Added manual argument parsing to correctly capture the limit value and strip it from the search query. 2. **Enhanced Regex Search**: * Improved `extractRegexPatterns` to support whole-query regex patterns (e.g., `re:^git commit`), allowing spaces in regex. * Fixed a bug where regex tokens (like `.*`) were passed to the SQL layer, leading to zero results. Now, when a regex is detected, the SQL query is cleared to fetch raw entries for proper filtering in Go. * Increased the default search limit when using regex to ensure a higher recall rate before Go-side filtering. 3. **TUI Table Layout Fix**: Sanitized multi-line commands in the ASCII table output by replacing newlines with spaces. This prevents the table layout from breaking when displaying multi-line scripts while preserving the full command content. 4. **Configuration**: The `--limit` flag is now correctly respected in both the data retrieval and display phases.
Author
Copilot AI
added a commit
to iteria-systems/hishtory
that referenced
this pull request
Mar 8, 2026
…dworken#347, ddworken#337, ddworken#331, ddworken#333, ddworken#297 Co-authored-by: yoplait2 <3725861+yoplait2@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #336
This PR introduces support for Regex-based searching in hishtory. It allows users to perform precise matching using regular expressions instead of the default fuzzy matching.
It also integrates this feature into the TUI with a new toggle mode.
Added support for
regex:andre:prefixes in search queries.Implemented
extractRegexPatternsto correctly parse regex patterns from the query string, preserving escape characters (e.g.,\.sh$).Implemented
filterByRegexto filter history entries using Go'sregexppackage after fetching results from the database.New Mode: Added a
regexModestate to the TUI model.Visual Indicator: When Regex mode is enabled, the prompt changes to
Search Query: [REGEX] >.Automatic Prefixing: When in Regex mode, the user's input is automatically treated as a regex pattern (internally wrapped with
re:).Keybinding: Added
Ctrl+g(default) to toggle Regex mode on/off.Help Menu: Updated both
ShortHelp(footer) andFullHelp(Ctrl+h) to display the new keybinding.Layout: Adjusted the
FullHelplayout to includeToggleRegexin the second column for better visibility.go build . && ./hishtory installCtrl+r.Ctrl+g. You should see the[REGEX]indicator appear.^git(Commands starting with git)\.sh$(Commands ending with .sh)docker.*runCtrl+hto verify the keybindingctrl+gis listed in the help menu.Ctrl+g)