elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.74k stars 303 forks source link

fish-like autosuggestion #322

Open aeosynth opened 7 years ago

aeosynth commented 7 years ago

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!

xiaq commented 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.

dmix commented 5 years ago

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

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

deathtrip commented 4 years ago

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

howdoicomputer commented 3 years ago

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

VarLad commented 3 years ago

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

swinchen commented 3 years ago

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

I couldn't agree more.

rdw20170120 commented 3 years ago

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.

krader1961 commented 3 years ago

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.

star-szr commented 3 years ago

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.)

krader1961 commented 3 years ago

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.

rdw20170120 commented 3 years ago

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

zzamboni commented 3 years ago

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.

aca commented 2 years ago

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

xiaq commented 1 year ago

@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:

xiaq commented 1 year ago

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.

balthild commented 1 year ago

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

doanngochieuo commented 1 month ago

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)