Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag to limit history --search results #3244

Closed
krader1961 opened this issue Jul 16, 2016 · 6 comments
Closed

add flag to limit history --search results #3244

krader1961 opened this issue Jul 16, 2016 · 6 comments
Assignees
Milestone

Comments

@krader1961
Copy link
Contributor

While working on fixing other problems with the history command it occurred to me that there really should be a flag to limit the number of search results to the n most recent commands. I was used to having such a capability when I used zsh and wrote my own history wrapper function when I switched to fish in order to have a similar capability. This would be similar to git log -nnn and far more efficient than piping the output of history -search through head -nnn or directly iterating over $history in a fish function.

@krader1961 krader1961 added this to the fish-future milestone Jul 16, 2016
@krader1961 krader1961 self-assigned this Jul 16, 2016
@floam
Copy link
Member

floam commented Jul 16, 2016

I find it hard to make an argument for search options for history when we provide string. Similarly, I find it strange to be providing further special tooling on history for limiting the output here.

I don't really see how this like the git completion optimization. Is there a prompt or something that'd suddenly stop being laggy? Because it's not really slow to just use $history for me.

> string split "\n" -- $history[1..500]  | wc -l
     531
> echo $CMD_DURATION
10

I think this would need to be taking multiple seconds to empathize with.

@floam
Copy link
Member

floam commented Jul 16, 2016

You wouldn't want to use head, not because it's slow but because you'll mess up multiline commands.

Iterating is fine and that should be how people access history anyhow. The history command has been mostly useful for user-friendly deletion.

$ for i in $history[1..500]; echo $i; end
...
$ echo $CMD_DURATION
72

@krader1961
Copy link
Contributor Author

How would you get the timestamp; e.g., history -t, with your example using string? And, as you noted, piping the output through head or tail is slow and doesn't correctly handle multiline commands. Also, slicing isn't as simple as you suggest given the current behavior that a slice endpoint must be a valid index. So if you fewer than 500 entries that fails. 95% of time time I just want to see the recent history to jog my memory.

@floam
Copy link
Member

floam commented Jul 16, 2016

How would you get the timestamp; e.g., history -t, with your example using string?

We don't currently expose the timestamp through the $history interface - so I don't think I could. This isn't related to the speed of history, just something we don't do yet that we ought to figure out.

I suppose we could provide another magic array. [timestamp1, timestamp2... ] seems pleasant enough but if someone finds an item in $history and tries to look it up in $historyplus interactively they're asking for pain.

So you'd want to have this array have the same entries it does now but also provide the timestamps. This seems nice:

> echo $exthistory[-5]
make install fish #7/15/2015 4:45PM

I was actually considering assembling just that after the fact just in history.fish for the output that we run through the pager now, because it moved the timestamp away from the left side, was easier to find with a regex, made the lines able to run through eval/fish -n directly, and I thought it would be nice if for display purposes the output could entirely be ran through fish_indent --ansi to syntax highlight them, especially with the comment coloring being not bad at all for the timestamp display.

@floam
Copy link
Member

floam commented Jul 16, 2016

Also, slicing isn't as simple as you suggest given the current behavior that a slice endpoint must be a valid index.

You could handle the errors and stop the loop in the second example or use count on $history if that's not slow.

@floam floam modified the milestones: next-2.x, fish-future Aug 2, 2016
@krader1961 krader1961 modified the milestones: fish 2.4.0, next-2.x Sep 20, 2016
@krader1961
Copy link
Contributor Author

With PR 3399, coupled with the three previous changes to the history command, it's now possible to do something I've wanted since I started using fish a year ago:

alias h 'builtin history search -15 --show-time="%a %m-%d %R  "'

Now I can type h to see the fifteen most recent commands I ran and when. More useful is something like this to show the most recent git commands I ran:

$ h -p git
Wed 09-21 13:42  git push
Wed 09-21 13:42  git diff
Wed 09-21 13:42  git status
Wed 09-21 13:41  git reset head src/builtin.cpp
Wed 09-21 13:41  git checkout src/builtin.cpp
Wed 09-21 13:41  git diff --staged
Wed 09-21 13:39  git log --stat -1000
Tue 09-20 22:32  git commit -a
Tue 09-20 22:20  git show-branch
Tue 09-20 21:07  gitvim
Tue 09-20 21:01  git diff head~1
Tue 09-20 20:57  git push --set-upstream origin history-search-limiting
Tue 09-20 20:45  git checkout share/completions/history.fish
Tue 09-20 20:45  git reset share/completions/history.fish
Tue 09-20 20:37  git stash pop

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants