63

I recently noticed 2 features in Fish and was wondering if anyone knew if these were also available in Bash?

Syntax highlighting

ss #1

Specifics:

  • You'll quickly notice that fish performs syntax highlighting as you type. Invalid commands are colored red by default:
  • A command may be invalid because it does not exist, or refers to a file that you cannot execute. When the command becomes valid, it is shown in a different color
  • fish will underline valid file paths as you type them
  • This tells you that there exists a file that starts with 'somefi', which is useful feedback as you type.

Autosuggestions

ss #2

Specifics:

  • fish suggests commands as you type, and shows the suggestion to the right of the cursor, in gray.
  • It knows about paths and options
  • To accept the autosuggestion, hit right arrow or Control-F. If the autosuggestion is not what you want, just ignore it.
slm
  • 369,824
  • 5
    About the closest analog that bash has is autocompletion. Unfortunately, fish's scripting is so elementary that it's a very poor substitute for the sort of things I do routinely with bash. – DopeGhoti Jan 15 '14 at 02:08
  • 1
    @DopeGhoti - hence my asking the Q 8-) – slm Jan 15 '14 at 02:10
  • and to think I was about to wonder when @slm would come by and answer this with an excellent explanation for you... I wonder if there's a zsh version. – strugee Jan 15 '14 at 03:13
  • @strugee - I was wondering if me asking a Q I didn't know the A to would throw everyone off 8-). Maybe the existence of the Q w/o an A will guilt some Bash devs into making it. – slm Jan 15 '14 at 03:15
  • @slm - yes, yes it did. although if it appeared in any shell besides fish, I'd bet money it appears in zsh. – strugee Jan 15 '14 at 03:41
  • @slm As a general rule we don't get tangled up with bash-completion (and similar) -- that's maintained by some members of the Debian project. I don't think anyone on that list (especially Chet) could be persuaded to implement something like this in the core codebase when there are a lot more important things we need to get through the door for 4.3-rc3. It would certainly be extremely difficult to do this within the confines of the existing code. If you do something, though, please feel free to send it in: bug-bash@gnu.org :-) – Chris Down Jan 15 '14 at 05:24
  • You could also use history-search-(up|down) to navigate commands beginning with what you just typed. This would mean your workflow would be to type something, and use history-search-up to get the last match beginning with that, which I assume is fairly similar in functionality to fish. You could also use reverse-i-search, but that is slightly more rigid, and doesn't handle inline modifications to the input well. – Chris Down Jan 15 '14 at 05:30
  • @ChrisDown - thanks for mentioning these bits. I've lived w/o it for this long, just thought these were nice features (at least on the surface) as I said to Gilles in chat, until you use a feature such as this it's hard to gauge how useful they'l' end up being. – slm Jan 15 '14 at 05:36
  • 3
    Try it over a high latency ssh link, you will come to hate the inline features pretty fast. – llua Jan 15 '14 at 05:40
  • @slm I don't think it's a matter of usefulness, per se, but a matter of priority. There are a lot of known bugs to fix which are going out with 4.3. There is, as usual, not a great increase in functionality, because there is a general desire to maintain the shell in a state where it is familiar, and allow others to use more divergent (zsh, fish, etc) shells if they want more esoteric functionality. Visual changes are not likely to be well received, especially those involving the use of colours, when bash must be able to run on extremely limited displays. – Chris Down Jan 15 '14 at 05:40
  • @ChrisDown - Yes I'd rather effort be spent on bugs vs. features, I hadn't realized there were that many bugs in Bash. – slm Jan 15 '14 at 05:44
  • @slm Take a look here, I think you'll get an idea of what's going on for 4.3. :-) – Chris Down Jan 15 '14 at 05:50
  • @ChrisDown - that's a pretty long list... – slm Jan 15 '14 at 05:53
  • 1
    @slm Most of those are corner cases, some nastier than others, but it can be pretty bad when you are deployed in a lot of environments. The "killer features" for 4.3 are cd -@, wait -n, globasciiranges, and $BASH_COMPAT, which a lot of people wanted. Almost all the rest is just firefighting. – Chris Down Jan 15 '14 at 05:58
  • @ChrisDown to get the up/down arrows to complete the commands starting with what you've typed, you need to have "\e[A": history-search-backward and "\e[B": history-search-forward in your ~/.inputrc right? – terdon Jan 15 '14 at 13:27
  • @terdon Er, yes, I meant history-search-(backward|forward), not up/down :-) My brain was clearly not switched on at that point. You can either do it using inputrc (affects all readline applications), or by calling bind (only affects bash). – Chris Down Jan 15 '14 at 13:31
  • 1
    @strugee, there is a zsh syntax highlighter - https://github.com/zsh-users/zsh-syntax-highlighting, I found it through the very cool oh-my-zsh. – Joe Block Feb 17 '14 at 03:02
  • @JoeBlock thanks! I'm an avid oh-my-zsh user but hadn't found that – strugee Feb 17 '14 at 04:23
  • 1
    @strugee, you may also want to check out antigen. It will load oh-my-zsh plugins/themes, loads non-oh-my-zsh bundles, will load bundles straight from git, lets you make changes dynamically without having to open new Terminal/iTerm windows and is pretty much awesome. See https://github.com/zsh-users/antigen for more. – Joe Block Feb 17 '14 at 22:21
  • This really two questions in one. Can we close it or edit it? – Flimm Jan 04 '22 at 16:46

3 Answers3

24

As mentioned in here, it can be achieved through ble.sh

# Quick TRIAL without installation
# requires the commands git, make (GNU make), and gawk

git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh source ble.sh/out/ble.sh

Here is a quick demo of Bash with blesh.

enter image description here

For more details see: README of Ble.sh

8

Unfortunatly not. But I predict, that bash will massively slow down if you try to implement these features. Perhaps that's why noone "ported" these features yet.

The nearest I found was https://github.com/dvorka/hstr, a shell suggestion box


aside bash:

I didn't tested it, but the only "ported alternative" that I found was written for zsh: https://github.com/zsh-users/zsh-autosuggestions

Some qwant'ing also lead me to https://websetnet.com/shell-packs-power-python-bash/ and https://github.com/xonsh/xonsh alias http://xon.sh, perhaps it also supports that out of the box

... but, I'm quite sure you're not interested in other alternatives to bash, because then you could just switch to fish ;)

  • 1
    I don't agree about alternatives, in fact while switching from bash to fish implies using a quite different syntax for scripting, zsh basically supports the same syntax as bash, and so switching to it is quite straight forward. – Treviño Jun 19 '20 at 18:39
1

I'm not sure about Bash highlighting but Bash's Auto-Complete feature is likely to Auto-Suggesting as you mentioned.

Even though Bash's Auto-Complete couldn't show suggestions as you want, but it actually does fill the content when you press [TAB]. If there are many choices for completing content, you press [TAB] twice and it shows all the options.

For example:

$ cat /etc/pa[TAB]

=> nothing happens

$ cat /etc/pa[TAB][TAB]
pam.d/       passwd       paths        paths.d/

=> shows all files/dirs start with "/etc/pa"

You can configure to make auto-complete with any command, parameters, files/directories..., or play with it like programming
More information at: http://www.linuxjournal.com/content/more-using-bash-complete-command

If you want to jump to a past command, press ^R then type some chars:

(reverse-i-search)`cd': cd ..

=> jump to last command start with "cd"

I know this is not exactly you want but that nearly do the same and help you convenience enough.

incous
  • 39
  • 11
    Thank you for taking the time to answer this and offer this suggestion. I'm familiar with this feature and use it daily, the feature I wanted was that it would do it dynamically w/o the need to hit the [TAB][TAB] to initiate it. – slm Feb 20 '14 at 16:07