DEV Community

Discussion on: Zsh Tricks to Blow your Mind

ikirker profile image
Ian Kirker

I don't zsh for similar reasons to yours in number 7: I definitely can't use it in some of the environments I work in, so I haven't really put any effort into using it anywhere. And I think it's useful to know what comes from where.

So, as an addition to this, some notes on equivalents that work in bash:

2: You can set this up for bash using the readline initialisation file .inputrc file in your home directory, or using bind commands in your shell startup files. I use the bind method because it doesn't affect other programs using the readline library that way. (E.g. the mysql and sqlite clients.)

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
Enter fullscreen mode Exit fullscreen mode

Ctrl-R also works in bash for expanding partial commands into history entries, though slightly differently.

3: I don't think this is a good idea either, but I thought it might be possible to set up in bash by setting the command-not-found handle:

function command_not_found_handle() {
   if test -d "$1"; then
      cd "$1"
      echo "Found directory '$1', cd-ing..." >&2
      echo "$0: $1: command not found" >&2
Enter fullscreen mode Exit fullscreen mode

Unfortunately it turns out this is run in a separate execution context to the shell it comes from, so the cd command can't take effect as intended.

I'm not sure there's an approach that would work.

7: I do this in bash using the readline kill buffer; usually using Ctrl-A to skip to the beginning of the line, then Ctrl-K to cut the line into the buffer. Then later, I can use Ctrl-Y to paste it back.

These keyboard shortcuts also work in zsh, because although zsh doesn't use the readline library, the equivalent zle apparently implements a lot of the same features.

An extensive plugin library is probably handy, but it's worth knowing that a lot of the stuff in there can also be implemented in bash, and there's an equivalent oh-my-bash to oh-my-zsh.

Zsh's line editing and display capabilities seem somewhat more sophisticated than bash's, definitely, so I think some things just can't be ported. The display-suggestions-as-you-type thing, particularly, I don't think has a bash implementation.