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

Implement history search --reverse #4375

Merged
merged 2 commits into from Sep 14, 2017
Merged

Implement history search --reverse #4375

merged 2 commits into from Sep 14, 2017

Conversation

@krader1961
Copy link
Contributor

@krader1961 krader1961 commented Sep 5, 2017

It should be possible to have history search output ordered oldest to
newest like nearly every other shell including bash, ksh, zsh, and csh.
We can't make this the default because too many people expect the
current behavior. This simply makes it possible for people to define
their own abbreviations or functions that provide behavior they are
likely used to if they are transitioning to fish from another shell.

This also fixes a bug in the history function with respect to how it
handles the -n / --max flag.

Fixes #4354

It should be possible to have `history search` output ordered oldest to
newest like nearly every other shell including bash, ksh, zsh, and csh.
We can't make this the default because too many people expect the
current behavior. This simply makes it possible for people to define
their own abbreviations or functions that provide behavior they are
likely used to if they are transitioning to fish from another shell.

This also fixes a bug in the `history` function with respect to how it
handles the `-n` / `--max` flag.

Fixes #4354
@floam
Copy link
Member

@floam floam commented Sep 5, 2017

Why not just flip the behavior for 3.0? Like you say most other shells order from oldest to newest, and if people think that's a better way to do things, why not just have fish do that, rather than add a flag?

Loading

src/history.cpp Outdated
@@ -1520,42 +1529,39 @@ void history_t::save(void) {

// Formats a single history record, including a trailing newline. Returns true
// if bytes were written to the output stream and false otherwise.
static bool format_history_record(const history_item_t &item, const wchar_t *show_time_format,
bool null_terminate, io_streams_t &streams) {
static void format_history_record(const history_item_t &item, const wchar_t *show_time_format,
Copy link
Member

@faho faho Sep 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is wrong - it doesn't return anything anymore.

Loading

@faho
Copy link
Member

@faho faho commented Sep 5, 2017

Why not just flip the behavior for 3.0?

Personally, when I look at the history, I use the history function, which auto-pages. And my pager (less) stays at the top. So newest-to-oldest is what I want, since that means I see the newest stuff first.

If I didn't page it, I'd want it the other way around so I wouldn't have to scroll to see the new stuff. But I believe the common case is to use a pager.

So this looks good to me.

Loading

@floam
Copy link
Member

@floam floam commented Sep 5, 2017

OK, that makes sense to me @faho, you're right. I also use a pager and wouldn't want to have to scroll to the bottom.

Loading

@floam
Copy link
Member

@floam floam commented Sep 5, 2017

Couldn't someone avoiding the fish history pager just as easily abbr/alias in a tac or (bsd) tail -r command to reverse the output as they could do such to prefer this reversed mode? Is there sufficient need to offer a reversed output mode specifically on this builtin?

Loading

@faho
Copy link
Member

@faho faho commented Sep 6, 2017

Couldn't someone avoiding the fish history pager just as easily abbr/alias in a tac or (bsd) tail -r command to reverse the output as they could do such to prefer this reversed mode? Is there sufficient need to offer a reversed output mode specifically on this builtin?

That's a philosophical argument, and it's not invalid.

However, given that there's two mutually exclusive ways to do this - my system doesn't have tail -r, and apparently BSD-ish systems don't have tac - I'd prefer if we offered one way that worked everywhere.

I consider this a failure of POSIX - not by specifying something stupid ($POSIXLY_CORRECT, anyone?), but by specifying too little.

Loading

@krader1961
Copy link
Contributor Author

@krader1961 krader1961 commented Sep 7, 2017

... and apparently BSD-ish systems don't have tac - I'd prefer if we offered one way that worked everywhere.

Correct, macOS for example, does not have tac. And tail -r is problematic because there is no way to unambiguously say you want every single line. You have to instead provide an absurdly large -n value. Too, people who want the output sorted oldest to newest (like every other shell does) shouldn't have to pay a performance penalty to get it.

Loading

@krader1961
Copy link
Contributor Author

@krader1961 krader1961 commented Sep 7, 2017

Also, tac and tail -r mangle multiline commands. There isn't any sensible way to do this by piping the output of history through another command even if the performance penalty was acceptable.

Loading

@krader1961
Copy link
Contributor Author

@krader1961 krader1961 commented Sep 7, 2017

Also, regarding the default history function behavior of piping the output through a pager. That has it's own problems. Most notably if your pager uses the alt-screen feature when you exit the pager the contents are no longer visible. I long ago configured less to not do that but that is something the average user won't bother with. Especially since doing so requires using less's --no-init flag or creating custom terminfo definitions.

It is also very rare that I want to see more than the most recent 10 to 20 commands. Which is why I use an alias named h that calls builtin history -n20.... If I want more results I only need to invoke it with a larger limit and can append |less. Which, because I have run abbr l less, means I only need to type two more characters. And scrolling to the bottom requires just typing G. So while I can appreciate that the default behavior is friendly to typical users it isn't friendly to a power user. This change simply makes it possible for power users to get behavior that is better suited to their needs.

Whenever the choice is between being friendly to average users or power users we should always favor the former. But that doesn't mean we can't or shouldn't provide ways to meet the needs of power users if doing so can be done without making fish less friendly for the average user.

Loading

@floam
Copy link
Member

@floam floam commented Sep 7, 2017

OK, seems reasonable.

Loading

@faho faho added this to the fish-3.0 milestone Sep 8, 2017
@mqudsi
Copy link
Contributor

@mqudsi mqudsi commented Sep 10, 2017

<offtopic>

and apparently BSD-ish systems don't have tac

I actually just tired of that limitation and published a cross-platform, MIT-licensed tac last week:
https://neosmart.net/blog/2017/a-high-performance-cross-platform-tac-rewrite/ (and github link)

</offtopic>

Loading

@zanchey
Copy link
Member

@zanchey zanchey commented Sep 14, 2017

@faho, are you happy with this?

Loading

@faho
Copy link
Member

@faho faho commented Sep 14, 2017

@zanchey: Yeah, I'm happy.

Loading

faho
faho approved these changes Sep 14, 2017
@floam floam merged commit ee1d310 into fish-shell:master Sep 14, 2017
1 check passed
Loading
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants