zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.95k stars 1.86k forks source link

Match commands that begin with whitespace #553

Open ejuarezg opened 4 years ago

ejuarezg commented 4 years ago

Is your feature request related to a problem? Please describe.

I like to prepend my commands with spaces in order to not save them to the history and prevent clutter. However, no suggestions, besides those that begin with whitespace, are given when I type commands with leading whitespace.

Describe the solution you'd like

An option that can be enabled that removes the leading whitespace from a typed command and matches the rest of the command with an entry in the history.

Describe alternatives you've considered

I've considered not prepending commands with spaces so that the suggestions work.

Additional context

I'm not familiar with ZSH scripting or else I'd give it a go. I think that this enhancement would interfere with history entries that begin with whitespace.

AnimiVulpis commented 3 years ago

I have no solution, but a workaround that I am using (for commands that I don't want to go into the history e.g. containing passwords)

  1. Type command and use completion feature
  2. Hit CTRL-A which should place the cursor at the beginning of the line
  3. Add the space and execute away

Maybe this helps you (it works for me)

ejuarezg commented 3 years ago

Thanks for your comment @AnimiVulpis. That's the same workaround I've been using. I'd just be a nice enhancement to have that as an option in the plugin.

stepnem commented 1 year ago

FWIW, here's what I've been using: https://github.com/stepnem/zsh-autosuggestions/commit/ce7ad0e8d4579f6e409b26683142fb1f2239ab51

Maybe it's not the best way to do it (I'm not that familiar with the code), but it works for me.

I didn't introduce a new option, as I don't see why anyone would prefer the current behavior.

ejuarezg commented 1 year ago

@stepnem Your commit was the solution I was looking for. Thanks!