I love the fish shell and use it exclusively in MacOS but I use bash everywhere else because its the only thing installed. Having felt the pain of maintaining configuration files for the two shells, I've decided to stop using fish, and fall back to bash instead. To make it as painless as possible, which configuration options / plugins / etc should I be using with bash to make it as close to fish as possible?

Things I miss most:

  • auto completion support: fish remembers all my commands, does completions on partial (sometimes huge) commands, seems to understand all the cmd-line apps I use and offers completions on their commands, etc. For each command fish shows in a dimmed color the command it would auto-complete to if I were to hit tab.
  • git support: fish shows me whether I am in a github repository, the name of the branch, and whether it has been modified or is clear using nice colors next to my username@hostname, I would love to have this on bash as well
  • google.se/… – Hannu Jul 31 '17 at 14:44
  • Almost everywhere bash is installed, it uses GNU readline for auto-completion & history. You can type tab to complete a command, or Ctrl+R, then any part of a previous command to auto fill it – jpaugh Jul 31 '17 at 15:16
  • 2
    Have you considered installing your own, private, copy of fish? Fish makes this really easy since it looks for its completion scripts, auto loaded, functions, and other config files relative to where you install it. So just ./configure --prefix=$HOME/fish; make install. Then symlink ~/bin/fish to ~/fish/bin/fish or add ~/fish/bin to your PATH. – Kurtis Rader Jul 31 '17 at 20:57

There are many options for configuring bash. I use the following commands to give easy command history access:-

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

These set the Up and Down arrows to scan up and down the command history for commands beginning with the characters before the cursor on the command line (as TCC does in Windows).

As for the prompt, you can put commands to be run each time the prompt is output. I use:-

PS1="\`curspos -n>/dev/tty\`\`[ \$BASH_LEVEL != 1 ]&&echo \"[\$BASH_LEVEL]\"\`\\t[\\w/]\\\$ "

This calls two commands on each prompt:-

  • curspos is a script I wrote to check the cursor position and output a new line if not in the first column (I got annoyed with unnecessary blank lines).
  • The BASH_LEVEL checks precede the prompt with the level in square brackets if it's not 1, so it's immediately obvious if you are in a child shell (eg [2]15:55:32[~/]$).

Neither of these answers your requirement directly, but they illustrate the power that you can use in the prompt string. In your case you can simply prepend a script or function (such as gitcheck) to execute before the rest of your prompt, and this can output any information you want to see in the format you want as part of the prompt.

I would finally comment that fish is available in many Linux distributions (eg it's in the Ubuntu repository), so you need do these bash customisations only if you are prevented from installing packages.

  • Even if OP is prevented from installing packages through the package manager, building from source might be an alternative. – a CVn Jul 31 '17 at 15:11
  • @MichaelKjörling I believe the OP's concern with fish is that it isn't installed by default, and requires customizing (potentially) many systems. – jpaugh Jul 31 '17 at 15:49
  • 2
    @jpaugh - My final point was that the bash customisation will itself require a certain amount of work, so it might be easier to install fish if that's an option. – AFH Jul 31 '17 at 15:58

Regarding auto-completion, bash uses GNU Readline to provide tab-completion, and history lookup & completion. Tab completion works for command names, files, and — for any commands which have completion scripts — options and arguments. Use Up or Down to move through the history linearly; or, to search, type Ctrl + R and any part of the command you remember. Readline is installed almost everywhere bash is, especially true for modern OSes.

To answer your Git concerns, Git itself includes scripts to color the prompt, and perform tab-completion for the bash shell, and others. When I installed Git for Windows, the bash program distributed with it was pre-cooked to use these automatically.

If you're familiar with bash, it probably isn't difficult to add a git prompt on Mac. Bash generates its prompt from the contents of the PS1 variable. It allows you to execute an arbitrary function to generate parts of the prompt, which allows these clever scripts to run. Like other shells, bash relies on the underlying terminal emulator to produce color. It simply passes the text you set for the prompt to the terminal emulator. Just add the right ANSI codes to the PS1 prompt, and you'll get color output.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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