Open aeosynth opened 7 years ago
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.
ZSH autosuggestions might be another good source of inspiration. It works really well:
Any progress or ETA on this? It's the one feature i miss in elvish.
Something I am currently missing while demoing Elvish is being able to see autosuggestions for directories as I type paths for cd
.
Any ongoing effort? I really like elvish, but can't shift from fish without some kind of auto-suggestion
Any ongoing effort? I really like elvish, but can't shift from fish without some kind of auto-suggestion
I couldn't agree more.
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.
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.
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.)
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.
I like the simple invocation of suggestions/search with an explicit keystroke. I must investigate using fzf
. Thank you for sharing your observations too.
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.
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
.
@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.
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.
Is it possible to implement this feature in the user-space?
Is it possible to implement this feature in the user-space?
it is, if elvish provides a function for user to render current command at will, say cmd_render(edit:current-command, last_similar_cmd_in_history)
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!