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

Allow overriding filter and search modes from CLI #635

Merged
merged 5 commits into from Dec 18, 2022

Conversation

pdecat
Copy link
Contributor

@pdecat pdecat commented Dec 3, 2022

This PR allows overriding filter and search modes from CLI arguments:

# atuin search -h | grep overriding
      --filter-mode <FILTER_MODE>    Allow overriding filter mode over config [possible values: global, host, session, directory]
      --search-mode <SEARCH_MODE>    Allow overriding search mode over config [possible values: prefix, full-text, fuzzy]

The bash up key bindings are updated to always use session filter mode when invoking atuin, and that choice may not be acceptable by other.

TODO:

  • decide what to do regarding up key bindings
  • also update fish and zsh up key bindings

bind -x '"\e[A": __atuin_history'
bind -x '"\eOA": __atuin_history'
bind -x '"\e[A": __atuin_history --filter-mode session'
bind -x '"\eOA": __atuin_history --filter-mode session'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, an alternative may be to have an additional configuration setting for filter mode when interactive mode is invoked via up key bindings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure which would be the best way to tell atuin that it invoked from the up key binding between:

  • adding a --shell-up-key-binding CLI argument:
    Suggested change
    bind -x '"\eOA": __atuin_history --filter-mode session'
    bind -x '"\eOA": __atuin_history --shell-up-key-binding'
  • defining a ATUIN_SHELL_UP_KEY_BINDING environment variable:
Suggested change
bind -x '"\eOA": __atuin_history --filter-mode session'
bind -x '"\eOA": ATUIN_SHELL_UP_KEY_BINDING=1 __atuin_history'

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I have a slight preference for hardcoding --filter-mode session in the init scripts, since up is for looking for a previous command and ctrl-r is for searching the history.

Using a --shell-up-key-binding argument is a good alternative if you want the configs to be in the config file instead of requiring users to customize the shell script. I don't think we should use an environment variable for this, you can always just make the CLI argument hidden from the help functions if that's the concern.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather configure this in our config file, and globally for all shells (not just bash). I'd also be pretty happy for --shell-up-key-binding to be how it's invoked!

I have a slight preference for hardcoding --filter-mode session in the init scripts, since up is for looking for a previous command and ctrl-r is for searching the history.

I think generally I'd agree with you there @patricksjackson, but I'm also a little cautious to change defaults at this point without a strong opinion for why. Currently I mostly feel lukewarm on the topic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pdecat pdecat marked this pull request as ready for review December 3, 2022 15:52
Copy link
Sponsor Contributor

@arcuru arcuru left a comment

Choose a reason for hiding this comment

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

Thanks for writing this! I've had this on my backlog ever since I started using Atuin.

src/command/client/search.rs Show resolved Hide resolved
bind -x '"\e[A": __atuin_history'
bind -x '"\eOA": __atuin_history'
bind -x '"\e[A": __atuin_history --filter-mode session'
bind -x '"\eOA": __atuin_history --filter-mode session'
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I have a slight preference for hardcoding --filter-mode session in the init scripts, since up is for looking for a previous command and ctrl-r is for searching the history.

Using a --shell-up-key-binding argument is a good alternative if you want the configs to be in the config file instead of requiring users to customize the shell script. I don't think we should use an environment variable for this, you can always just make the CLI argument hidden from the help functions if that's the concern.

@pdecat pdecat force-pushed the set_filter_and_search_mode_from_cli branch from c29d493 to 30511bc Compare December 12, 2022 23:18
Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

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

Thanks for this 🙌 Generally happy with it, just one small suggested then it's good to go imo

bind -x '"\e[A": __atuin_history'
bind -x '"\eOA": __atuin_history'
bind -x '"\e[A": __atuin_history --filter-mode session'
bind -x '"\eOA": __atuin_history --filter-mode session'
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather configure this in our config file, and globally for all shells (not just bash). I'd also be pretty happy for --shell-up-key-binding to be how it's invoked!

I have a slight preference for hardcoding --filter-mode session in the init scripts, since up is for looking for a previous command and ctrl-r is for searching the history.

I think generally I'd agree with you there @patricksjackson, but I'm also a little cautious to change defaults at this point without a strong opinion for why. Currently I mostly feel lukewarm on the topic

@pdecat
Copy link
Contributor Author

pdecat commented Dec 17, 2022

Hi, I've implemented the discussed changes:

  • add a --shell-up-key-binding hidden command argument,
  • add a filter_mode_shell_up_key_binding configuration option to allow customizing the filter mode used when atuin is invoked from a shell up-key binding,
  • update the fish and zsh scripts too (could not test them though).

I've also kept the default to be global to avoid messing with other people preferences.

It would be great if fish and/or zsh user could validate the changes, as I only use bash.

@pdecat pdecat requested review from ellie and arcuru and removed request for ellie and arcuru December 17, 2022 14:56
@pdecat pdecat force-pushed the set_filter_and_search_mode_from_cli branch from 1461768 to 303cc99 Compare December 17, 2022 15:40
…ell_up_key_binding configuration option to allow customizing the filter mode used when atuin is invoked from a shell up-key binding
@pdecat pdecat force-pushed the set_filter_and_search_mode_from_cli branch from 303cc99 to 3cea079 Compare December 17, 2022 15:58
Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

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

One last thing! Then I'm happy to get this merged

src/shell/atuin.zsh Outdated Show resolved Hide resolved
@ellie ellie enabled auto-merge (squash) December 18, 2022 18:17
@ellie ellie merged commit ed394af into atuinsh:main Dec 18, 2022
@pdecat pdecat deleted the set_filter_and_search_mode_from_cli branch December 18, 2022 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants