46

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.
19
  • 4
    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 2:08
  • 1
    @DopeGhoti - hence my asking the Q 8-)
    – slm
    Jan 15 '14 at 2:10
  • 3
    Try it over a high latency ssh link, you will come to hate the inline features pretty fast.
    – llua
    Jan 15 '14 at 5:40
  • 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 5:58
  • 1
    @strugee, there is a zsh syntax highlighter - github.com/zsh-users/zsh-syntax-highlighting, I found it through the very cool oh-my-zsh.
    – Joe Block
    Feb 17 '14 at 3:02
6

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

5

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.

1
  • 10
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.