elvish icon indicating copy to clipboard operation
elvish copied to clipboard

fish-like autosuggestion

Open aeosynth opened this issue 8 years ago • 16 comments

elvish has tab-completion, but the feature i miss most from fish is browser style as-you-type autocompletion, where typing a command will show a preview of an autocompletable command. requesting this!

aeosynth avatar Feb 16 '17 06:02 aeosynth

Autosuggestion in fish is backed by history instead of completion, so I am changing the title.

I am for this idea. Fish seems to have a sophiscated strategy for autosuggestion; I think we can start with a simple history match.

xiaq avatar Feb 16 '17 17:02 xiaq

ZSH autosuggestions might be another good source of inspiration. It works really well:

https://github.com/zsh-users/zsh-autosuggestions

dmix avatar Jul 07 '19 08:07 dmix

Any progress or ETA on this? It's the one feature i miss in elvish.

deathtrip avatar Sep 12 '20 11:09 deathtrip

Something I am currently missing while demoing Elvish is being able to see autosuggestions for directories as I type paths for cd.

howdoicomputer avatar Feb 17 '21 09:02 howdoicomputer

Any ongoing effort? I really like elvish, but can't shift from fish without some kind of auto-suggestion

VarLad avatar Aug 22 '21 16:08 VarLad

Any ongoing effort? I really like elvish, but can't shift from fish without some kind of auto-suggestion

I couldn't agree more.

swinchen avatar Sep 21 '21 14:09 swinchen

If you do autosuggestions, please do not imitate Fish's catastrophic mistake of making them always-on with no configurable way to turn them off. As discussed at length in the Fish issues, auto-suggestions are wonderful for a beginner, annoying for an intermediate user, and an absolute nightmare for many expert users. They are also a nightmare for any low-bandwidth or high-latency connection (remote SSH, etc.). I already dropped Fish, as have several other expert users I encountered, specifically because of Fish's poor implementation of auto-suggestions that can never be turned off.

rdw20170120 avatar Sep 21 '21 16:09 rdw20170120

Another data point.... I switched to Fish from zsh many years ago (around the time fish 2.1 was the current version). At first I absolutely hated the auto-suggestion feature because it was so unlike anything I was used to and asked if there was a way to disable it. After a couple of weeks I got used to it. Many months later I found it didn't really add much value and still wished there were a way to disable it.

When I switched to Elvish I didn't find miss Fish like auto-suggestions at all. I'm not opposed to implementing something like it but it definitely should be possible to disable it or make it an opt-in feature; i.e., not enabled by default.

krader1961 avatar Sep 22 '21 00:09 krader1961

Another data point: I followed this issue sometime last year after switching to Elvish. I don’t miss autosuggestions anymore. I really like the stock ctrl + r setup.

(Edit to add: I was using autosuggestions in zsh, not fish, but the point still stands.)

star-szr avatar Sep 22 '21 02:09 star-szr

Also, note that it is now easy to use fzf for selecting items from the history and with recent changes using it is as fast as the builtin Ctrl-R widget. See https://github.com/elves/elvish/issues/1053#issuecomment-859223554.

krader1961 avatar Sep 22 '21 02:09 krader1961

I like the simple invocation of suggestions/search with an explicit keystroke. I must investigate using fzf. Thank you for sharing your observations too.

rdw20170120 avatar Sep 22 '21 16:09 rdw20170120

I agree with @krader1961 about not missing this feature. I moved from Fish to Elvish, and I have found Elvish's command history search and location mode work a lot better than Fish's auto-suggestions. E.g. with Elvish, I can type the beginning of a command and press Up (or Ctrl-P with readline-bindings) and cycle through all the commands that start with the string I typed.

@howdoicomputer you said:

Something I am currently missing while demoing Elvish is being able to see autosuggestions for directories as I type paths for cd.

Have you used location mode? I find it so much more powerful than regular cd-completion mechanisms (including things like fzf). Once I have been to a directory once, I can just press Ctrl-L (or Alt-L with readline-bindings) and find it/switch to it with a few keystrokes. I barely use cd anymore! It's super powerful and an amazing feature of Elvish.

zzamboni avatar Sep 23 '21 07:09 zzamboni

Autosuggestion was very useful for me. Instead of invoking huge history(w/ fzf mostly) instead I first check autosuggestion and simply complete the command with bind -M $mode \cf forward-char.

image

aca avatar Dec 17 '21 03:12 aca

@aca Answering your question on the chatroom about where to start if you'd like to implement this:

The editor is made up of two layers. The lower-level layer pkg/cli is a general-purpose toolkit, and the pkg/edit wraps around it and provides Elvish-specific functionalities and API.

To implement the autosuggestion functionality, you'll change at least two places:

  • pkg/cli/codearea.go implements the widget for the main code area. It needs to support the concept of auto suggestions without implementing the code that generates all those suggestions. This can be implemented by adding a callback to CodeAreaSpec that gets called whenever the code changes and returns auto suggestion.

    CodeArea already has a concept of "pending code", which can be leveraged internally for auto suggestions. However I'd like auto suggestion to have a more subtle UI than the current pending code (which is used for completion and history), so it'd also make sense to remember whether the pending code is from an auto suggestion or not; this can be done by adding a boolean AutoSuggestion field to PendingCode and use a different style when that field is true.

  • pkg/edit/editor.go is where the high-level editor gets initialized. The NewEditor function calls a lot of other functions, some of which mutate the CodeAreaSpec. To implement auto suggestion, it probably makes sense to create another one of those functions, which initializes the new callback that returns auto suggestions.

xiaq avatar Jun 20 '23 18:06 xiaq

Another small but important bit about the implementation: auto suggestion should always be run asynchronously - if reading the history is slow, the editor shouldn't get stuck.

xiaq avatar Jun 20 '23 18:06 xiaq

Is it possible to implement this feature in the user-space?

balthild avatar Nov 05 '23 18:11 balthild