Something I've noticed is that osx users believe bash to be less capable than it is because of the poor out of the box configuration of bash on that platform (in addition to the ancient version installed). Particularly the tab completion stuff. It doesn't pop up menus and all that, but the ubuntu install of bash has a ton of context-sensitive tab completion stuff in it, and the git package properly installs __git_ps1 and very good tab completion (which even the homebrew git recipe on osx doesn't manage to do).
This is not to say that zsh doesn't have a lot more features, just that the comparison from the perspective of an osx user tends to be a lot more stark.
Indeed. Bash has, or can be configured, to have almost all the features listed in this article. The article is really a testament to the power of defaults. The bash maintainership is extremely conservative about enabling new features by default even when these features are unalloyed good.
For example, I contributed bracketed paste support to bash and readline. Yay! No more inadvertent command execution! No security problems pasting shell commands from web pages! You'd think we'd want that feature enabled by default, right?
Well, no. The feature will be off by default. For reasons.
While we're on the topic of non-bash shells, I recommend taking a look at Fish: http://fishshell.com/
I wrote a tutorial on how to install it on Mac OS X and Ubuntu: http://hackercodex.com/guide/install-fish-shell-mac-ubuntu/ For me, the chief advantage to Fish is that you get more functionality out-of-the-box than with most other shells, including zsh.
I also published two related projects for easily sharing Fish shell enhancements — Tacklebox https://github.com/justinmayer/tacklebox and Tackle https://github.com/justinmayer/tackle) — because I wanted a way for folks to be able to have access to multiple plugin repositories and easily share their favorite shell snippets.
A killer feature not listed here is global aliases. These are aliases that can be anywhere in a line. The most use I get out of this is from having
alias -g L=' | less '
which allows me to simply append "L" to a line to pipe the output to less.
ls L
The pattern of short all-caps global aliases for ' | command 's make building/editing pipelines really easy/fast.
alias -g C=' | wc -l '
alias -g A=' | ack-grep '
alias -g S=' | sort '
alias -g JQL=' | jq -C | less'
ls **/*png L
ls **/*png A -v regex C
curl $site JQL
putting
bindkey '^g' _expand_alias
in your zshrc allows you to expand aliases with <C-g>
After that, the more dots you type, the more error-prone it is, as you start to have to carefully count exactly how many directories you have to go up to get to where you want.
A better alternative is a script that shows a list of parent directories and lets you select them by typing the number or letter associated with them.
For example, if your current directory is "/a/b/c/d/e/f/g/h", then the script would display something like:
List of parent directories:
1 - a
2 - b
3 - c
4 - d
5 - e
6 - f
7 - g
Please choose a directory: _
and you could type "3" to get to directory "c". That would be equivalent to typing "......", but much less error-prone and it'll save you the tedium of counting dots too.
Error prone isn't really that important in a shell when we're just talking about moving around. You type a bunch of dots which puts you in the region more or less -- plus I never really go from 8 directories deep to 2, (I doubt I even have an 8 directory deep section of my file tree) -- if I did I'd start from /, so it's more about 4 or 5 or so, in which case it's easy enough not to count but to know based on context. To each his own though.
The tab completion isn't limited to the beginning of file names either. Useful when many of your file names start with the same pattern but then diverge.
ls something<TAB>
will complete to
ls prefixSomething.sh
if it's unique enough. This is probably my single favorite zsh feature.
Having gotten used to ido in emacs, I must say that I am now disappointed in most all autocompletes. Shame it doesn't work in the shell. (Quick, someone prove me wrong! Please! :) )
The real magic of ido is the completion engine. It's not made super explicit in that video, but it's actually possible to complete on arbitrary subsequences of strings you want.
With my configuration (using the popular "flx-ido" matching engine), if you wanted to match "README.md", you could achieve this by just typing ED. Even though E and D aren't consecutive, E appears before D. (But "GOOD_EDITING_SOFTWARE" would be matched before "README.md", because it prioritizes consecutive matches and characters at the beginnings of logical groups of characters.)
One feature not listed there that use a lot is "setopt autocd". Just type in a directory name and hit Enter and it will automatically "cd" to it. No need to alias ".." to "cd ..".
I love that if you have vi key bindings active you can update the prompt when you change modes. I never used vi bindings in bash because I would become confused when I entered normal mode without realizing it. In zsh it was easy to configure my prompt to change colors and symbols when outside insert mode.
It seems to me that the only two features I can't get in my modern bash is completion of the kind cd /firstletters/firstletters/<tab> ==> /fullname/fullname and the keyboard navigable menus.
bash only needs better history manipulation. absolutely nothing else.
all those z shell features the only useful one (i.e. the only one that's impossible on bash) is the recursion (i typed star star, but hn hides it) hack.
and it's awful. because now you just learned something that you can't use anywhere else! and to search that same way in a shell script? though luck.
also it has less parameter then find. and find is available everywhere so you can use it in scripts.
(Shameless self-promotion) I'd like to recommend a small and unobtrusive config for ZSH: https://github.com/changs/slimzsh
It is almost a default ZSH, but with small tweaks here and there to make it even nicer. I hope that you find it useful :)
There's a variety of different things you can bind up-cursor to. It sounds like you want.
bindkey '\e[A' history-beginning-search-backward
Even better is the function in Functions/Zle/up-line-or-beginning-search To use that, you need to first do:
autoload -U up-line-or-beginning-search
zle -N up-line-or-beginning-search
You should check out https://github.com/tymm/directory-history then.
It makes your history matching sensitive to the directory you are in.
That means that commands will show up first which were typed in the directory you are in.
I don't want to miss this plugin and can't really understand why not everyone wants it. I guess I am a little biased though since I wrote that plugin ;)
I use C-r and C-s in bash, for incremental searching backwards and forwards. Takes less time to type these than reach across to the up and down arrow keys. Mind to stty stop undef to stop C-s from freezing your terminal, of course.
Zsh would probably be worth using, except for the fact that bash is almost everywhere, and I already know it very well. It's a tough one to call.
For menu complete with bash, the easiest is to add:
TAB menu-complete
inside of "~/.inputrc" then start a new shell to test it. Thats because it uses readline to handle command line (and inputrc configures readline).
Note: im not saying the experience is not better in zsh, just that both can do all this stuff. ive been switching between zsh and bash quite a few times myself over the last decade and use bash daily most of the time lately.
In my eyes:
zsh:
- nice and neat to configure/less bloat maybe
- powerful scripting language
- some scripting syntax requires zsh so when you get used to that... you write non-portable stuff ;)
bash:
- does approx everything zsh does and some more
- scripting language works everywhere because everyone has default to bash
- scripting language is slightly less powerful than zsh in some ways
- configuration is a little more all over the place (just like the .inputrc above)
Thus, all things considered, and given the improvements in bash over the last past .. 5 years or so - i'm using bash more often even thus zsh is also a very nice shell.
This is not to say that zsh doesn't have a lot more features, just that the comparison from the perspective of an osx user tends to be a lot more stark.