marlonrichert / zsh-hist

đź“ť Edit your Zsh history from the command line.
MIT License
148 stars 13 forks source link

Select multiple history entries #13

Closed dasebasto closed 2 years ago

dasebasto commented 3 years ago

Very nice plugin, thanks!

I'd like to delete ranges of command lines from the history.

The use case is that it usually takes a lot of trial and error before building the perfect complex one-liner (e.g. a text processing command with regex). I want to keep the good command in history and delete the incorrect tentatives.

Python slice notation syntax could be convenient:

e.g:

hist d [-3:]    # delete last 3 lines
hist d [-10:-2]   # delete last 10 lines, except the most recent one
hist d [1500:1510]   # delete lines with index 1500 to 1510

Maybe brackets can be omitted for an even more concise syntax.

Another suggestion, with probably less potential for popularity, but which would be practical in many cases:

hist d 60m # delete all commands from the last 60 minutes
marlonrichert commented 3 years ago

While I love Python and it slice syntax, I don’t think it’s suitable for a shell command. I might implement it like this:

hist d -3 -1     # delete last 3 lines
hist d -10 -2    # delete last 10 lines, except the most recent one
hist d 1500 1510 # delete lines with index 1500 to 1510

Or perhaps with the indexes reversed.

I probably won’t implement your suggestion with minutes. That seems prone to errors.

marlonrichert commented 2 years ago

It's there! hist now accepts any number of selection arguments. So, to specify a range, just use normal zsh brace notation:

hist d -{1..3}       # delete last 3 lines
hist d -{10..2}      # delete last 10 lines, except the most recent one
hist d {1500..1510}  # delete lines with index 1500 to 1510

As you can see, the order of the arguments does not matter.

marlonrichert commented 2 years ago

PS: If you enjoy using my software, please consider sponsoring me. 🙂