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

Feature request: Fish-like autocompletion and autosuggestion #894

Closed
seagle0128 opened this issue Feb 4, 2017 · 26 comments
Closed

Feature request: Fish-like autocompletion and autosuggestion #894

seagle0128 opened this issue Feb 4, 2017 · 26 comments

Comments

@seagle0128
Copy link

Hi, I like this project and use recently. I used Fish and ZSh. I'd like request some new features I missed very much: Fish-like autocompletion and autosuggestion. Some guys implemented in Zsh already. is it possible to implement in Bash? Thanks!

@nwinkler
Copy link
Member

nwinkler commented Feb 5, 2017

Can you please described what these features do? Without that, it will be hard to impossible to implement them.

@arimourao
Copy link
Contributor

I think he is referring to fish shell

@seagle0128
Copy link
Author

@arimourao yes. Could refer to fish shell.
And here is the implementation in zsh/oh-my-zsh.
https://github.com/zsh-users/zsh-autosuggestions
https://github.com/zsh-users/zsh-syntax-highlighting

@nwinkler
Copy link
Member

nwinkler commented Feb 9, 2017

Sorry guys, but I'm way too busy to read through these links and figure out what you're looking for.

If you're interested in having a feature added, please provide a concise description of what you're looking for. Or even better provide a Pull Request that implements the feature. Suggestions are great, but someone will have to implement it in the end.

No offence, but I don't have time for doing this guesswork.

@seagle0128
Copy link
Author

seagle0128 commented Feb 9, 2017

Okay. Let me explain the details.

What's I want exactly is Fish-like auto-suggestions as below.
The command suggestions come out automatically according to the history. It's very useful while typing the long commands. And you can also see the syntax color highlight of the commands in the screenshot.

autosuggestion

@arimourao
Copy link
Contributor

@seagle0128 it's interesting but I think this is an entire new project in its own. You or someone else interested in these features should port these to Bash. Only then bash-it could add these as plugins to be installed.

@nwinkler
Copy link
Member

Agreed. This looks like a useful feature, but if you take a look at the project, it looks like a huge undertaking. Not sure whether Bash supports the features required for making something like this happen.

@lfelipe1501
Copy link
Contributor

lfelipe1501 commented Jun 6, 2017

Hi @seagle0128 I would like to have in bash the zsh autocomplete but so far what I have found is this.

https://github.com/dvorka/hstr

I hope it works for you and that @nwinkler revises it to implement it in the framework.

Greetings. :bowtie:

@nwinkler
Copy link
Member

nwinkler commented Jun 7, 2017

This looks similar to fzf, which we already have a plugin for - allowing to search through your history for previous commands...

From what I've seen, the autocomplete functionality you're looking for is not easily possible in Bash...

BTW: I'm not sure why you think that I have to implement this. Feel free to provide a Pull Request if you have something you would like to see added.

@ShalokShalom
Copy link

I completely support the suggestion of @seagle0128

This is something very similar: https://github.com/scop/bash-completion

@nwinkler
Copy link
Member

Isn't the Bash completion you linked to exactly what we already have in Bash-it's completion functionality?

@ShalokShalom
Copy link

This is what i mean: https://asciinema.org/a/37390?t=16

@ericbaranowski
Copy link

I agree with you guys, I can't believe something like that doesn't already exist for bash. Like @nwinkler said, bash probably doesn't support the features necessary to achieve the functionality, otherwise it would exist already. However, based on all these comments I'm gonna look further into the port idea.

@ShalokShalom
Copy link

ShalokShalom commented Aug 22, 2017

I am on zsh now and very happy. Oh-my-zsh made it very easy to setup and https://github.com/zsh-users/zsh-autosuggestions add the functionality. One huge pro is that zsh is fully compatible with bash.
Solved for me..

@TimothyBramlett
Copy link

@ShalokShalom Nice, yeah I may need to the zsh route also. I love fish for its autocompletion but I hate that its not compatible with bash, which is used heavily for scripting that you are forced to use it.

@seagle0128
Copy link
Author

I agree. I switch to zsh a few months ago and am happy as well.

@nwinkler
Copy link
Member

Closing this now...

@bluz71
Copy link

bluz71 commented Mar 19, 2018

Personally I believe Bash/Readline's existing history-search-backward and history-search-forward options are just as useful and less distracting (at least to my eye).

Add the following to ~/.inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward

Type a partial command (one that you have already executed previously) then use the UP-arrow to navigate through all the commands that match the prefix (down to go forward). Whilst it doesn't look as sexy as Fish/Zsh auto-suggestion it is just as functional.

@nwinkler
Copy link
Member

Personally, I use fzf for that. If you install fzf and enable the fzf plugin, your Ctrl+R prompt turns into a fuzzy filter for command history, it will autocomplete previous commands as you type. I find this to be highly productive...

@benjamin-thomas
Copy link

Coming from a google search...

After seeing some advantages from fishshell over bash but still preferring a lot of bash idioms (!!, $!, $!:h, command completion with <ESC>*, etc.)

Oh...my...god!!!

@nwinkler, you just made my day!!

What an awesome tool fzf is!!

Combined with vim integration, I'm blown away..

@nwinkler
Copy link
Member

nwinkler commented Mar 31, 2018

Thanks for the kind words, @benjamin-thomas - happy to help.

fzf is indeed absolutely fantastic, one of the best shell tools I know.

In addition to the built-in functionality (Ctrl+R), the fzf plugin contains some common functions that I have adapted from the fzf Wiki, too.

I also use it ad-hoc for things like ls | fzf, together with the preview functions this is incredibly useful. Try this with the configuration from my dotfiles:

https://github.com/nwinkler/dotfiles/blob/0d5688368b6a15e701768305625a469e43170c47/home/.bash_profile#L18

# Use ag for feeding into fzf for searching files.
export FZF_DEFAULT_COMMAND='ag -U --hidden --ignore .git -g ""'
# Color: https://github.com/junegunn/fzf/wiki/Color-schemes - Solarized Dark
# Bind F1 key to toggle preview window on/off
export FZF_DEFAULT_OPTS='--bind "F1:toggle-preview" --preview "rougify {} 2> /dev/null || cat {} 2> /dev/null || tree -C {} 2> /dev/null | head -100" --color dark,hl:33,hl+:37,fg+:235,bg+:136,fg+:254 --color info:254,prompt:37,spinner:108,pointer:235,marker:235'

# Show long commands if needed
# From https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings
# Bind F1 key to toggle preview window on/off
export FZF_CTRL_R_OPTS='--bind "F1:toggle-preview" --preview "echo {}" --preview-window down:3:hidden:wrap'

@benjamin-thomas
Copy link

These are very, very nice ideas.

Very well done, and thanks for the share!

@iamnoskcaj
Copy link

I too, love the fish shell for its unobtrusive command suggestions, inline, as I'm typing. I got so used to it. It's nice zsh has something similar (as mentioned by @ShalokShalom). I am far more comfortable in a bash similar shell, and fish is a little out there for me.

@cojack
Copy link

cojack commented Feb 1, 2019

Impossible to achieve?

@akinomyoga
Copy link
Contributor

akinomyoga commented Feb 9, 2019

As far as I know, it's impossible unless readline (GNU Readline, the default line editor of GNU Bash) is modified or replaced by some other line editor. I actually implemented syntax-highlighting and autosuggestions in my bash configuration (akinomyoga/ble.sh), but it replaces readline with a line editor written in bash scripts so that some behaviors might be different from those in readline. Nevertheless, maybe you like ble.sh (if you don't want to implement a new line editor and autosuggestions for yourself).

(Edit) Note: ble.sh is completely orthogonal to bash-it which defines variables, aliases, functions and completions, so both of them can be loaded as:

# bashrc

[[ $- == *i* ]] || return 0
source /path/to/blesh/ble.sh --noattach

# user settings...

source "$BASH_IT"/bash_it.sh
((_ble_bash)) && ble-attach

@gilescope
Copy link

FYI pwsh is implementing auto-suggest in their PSReadLine project. (See fish branch)

I have a dream, that one day, bash too will have auto-suggest.

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

No branches or pull requests