GNU History Library. Node: Searching the History List

PREVMoving Around the History List UPHistory Functions NEXTManaging the History File

2.3.5: Searching the History List

These functions allow searching of the history list for entries containing a specific string. Searching may be performed both forward and backward from the current history position. The search may be anchored, meaning that the string must match at the beginning of the history entry.

Function: int history_search (char *string, int direction)
Search the history for string, starting at the current history offset. If direction < 0, then the search is through previous entries, else through subsequent. If string is found, then the current history index is set to that history entry, and the value returned is the offset in the line of the entry where string was found. Otherwise, nothing is changed, and a -1 is returned.
Function: int history_search_prefix (char *string, int direction)
Search the history for string, starting at the current history offset. The search is anchored: matching lines must begin with string. If direction < 0, then the search is through previous entries, else through subsequent. If string is found, then the current history index is set to that entry, and the return value is 0. Otherwise, nothing is changed, and a -1 is returned.
Function: int history_search_pos (char *string, int direction, int pos)
Search for string in the history list, starting at pos, an absolute index into the list. If direction is negative, the search proceeds backward from pos, otherwise forward. Returns the absolute index of the history element where string was found, or -1 otherwise.
PREVMoving Around the History List UPHistory Functions NEXTManaging the History File