TransWikia.com

is there any way to invert history_ignore in zsh?

Unix & Linux Asked by yahnweh.remixed on December 3, 2021

I’m trying to invert or reverse the HISTORY_IGNORE parameter. Specifically trying to only include certain things in the history file, instead of selecting certain ones to exclude.

For example, if I were to only include only commands prefixed with "recordthis ", that exactly what I want.

I don’t know if there’s a way to use anything like HISTORY_INCLUDE, which doesn’t exist as far as I know. I also don’t know if there’s a way to say HISTORY_IGNORE="(*|!recordthis *)", which I think I tried, without desired results.

One Answer

HISTORY_IGNORE is interpreted as a zsh wildcard pattern, so provided you set the extendedglob option, you can define

HISTORY_IGNORE='^recordthis*'

For zsh not to save entries that don't start with recordthis into $HISTFILE.

^ is the negation glob operator. See also the ~ except (or and-not) operator (also requires extendedglob):

HISTORY_IGNORE='*~recordthis*'

(ignore anything (*) except strings starting with recordthis).

Answered by Stéphane Chazelas on December 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP