For those who are not familiar with Z Shell, as well as those who are at the crossroads in choosing a shell for everyday tasks, this article is dedicated.
I must say, quite a lot of material has already been written about the benefits of zsh. As for this modest note, it is intended to show the reader the capabilities of both shells with specific examples of configuration files. The emphasis is on zsh, because, as the author understands, bash is usually suitable for initial use, it is better not to use zsh without your own settings.
Full author configuration files can be picked up from
github .
I. Best in shell - autocompletionThere is autocompletion in bash too, in our time you won’t surprise anyone. Especially good in this sense is bash-completion, which allows you to not only complement directory paths, but also effectively search for packages to be installed. If you have not previously used it, my advice to you: be sure to install it. Additional settings for this package is not required.
')
Zsh might surprise you, it really is. Perhaps auto-completion is one of its strengths. Immediately you need to note the fact that zsh is modular and to expand its capabilities you need to connect or in some cases install the necessary modules. In addition, you cannot do without individual configuration in zsh: modules will need to be included in your .zshrc. Let us turn to practical examples.
For ArchLinux, it’s better to install packages like bash-completion right away, which will allow you to use autocompletion in searching for packages with pacman and AUR: these are zsh-yaourt and zsh-packer. You can find them in the same AUR. Let's connect our autocompletion:
Already not bad, right? Honestly, I was not tempted by the prospect of a transition to zsh, because in general I was satisfied with bash. But the experiment showed: zsh is very convenient.
Ii. HotkeysAs far as I know, in bash hotkeys are not subject to change. However, it is possible that I am mistaken. These are the keys of the emacs editor known to all Linux users. They are taken as a basis and will work on any machine where bash is installed. Of course, no one will forbid you to use the arrows to move between characters or the delete key to delete a character — this is also in bash, and it does not need to be configured either.
Let's turn to zsh. Yes, as you probably already guessed: in zsh everything needs to be customized. Of course, it would be terrible if we had to customize every key - not at all! You can choose one of two styles, based on the more familiar to you: vi mode or emacs mode.
Recommendation: choose emasc to confidently use hotkeys on any machine with any shell, besides, bash is the most popular one all the same - be guided by it.
Of course, you can customize individual keyboard shortcuts as you like.
Example:
bindkey '\e[3~' delete-char
Iii. AliasesIt is very convenient to use aliases of various commands. Aliases are finely tuned in both bash and zsh. The difference is that in zsh you can use not only commands, but also assign file type extensions to individual applications. How is this useful? Thanks to this feature, zsh can even replace your file manager. See for yourself:
Note the lines starting with
alias -s . Now imagine: you are in the document directory and there is one or more of them with the .html extension. What do we usually do? Launch the browser, press Ctrl + O, select the file and view it. What do zsh aliases do? Just write the name of the document and it will be immediately opened in the browser.
To do this, a separate pick-web-browser module is first loaded.
Iv. Command historyAnd, of course, no user will challenge the usability of command history. Here, zsh is nothing special than bash. Configure it:
V. Other amenitiesFor zsh, there is one more curious thing: the zsh-syntax-highlighting plugin. ArchLinux users can install it from AUR, the rest can be downloaded from the project of the same name on github. Put it, and your terminal emulator will sparkle with new colors.
Initially, it is focused on any terminals - not only supporting 256 colors, so some colors may not look the way we like, but it can be fixed. The main file with the color settings is located on the path:
/usr/share/zsh/plugins/zsh-syntax-highlight/highlighters/main/main-highlighter.zsh . But there is no need to edit it directly (thanks,
ZyXI for pointing out an error).
Change the colors as you need in .zshrc and activate the plugin.
Example:
Also in zsh there is a very popular way of packing / unpacking archives. Enter the command extract myfile.tar - unpack the archive, enter the command pk tar myfile - pack the file into the archive of the specified format. So zsh can replace archiver?
To unpack, we enter in .zhsrc:
To create archives:
Vi. ResultsZsh is very convenient for everyday work and does a good half of the routine for you. But pay attention to the differences between these two shells. For example, in zsh after for it is necessary to insert a space, the numbering of arrays in zsh begins with 1, which is completely impossible to understand.
So, if you use the shell for everyday work that excludes scripting, use zsh. If you often have to write your own scripts, just bash! However, you can combine.
How to set zsh as the default shell for a single user:
$ chsh -s /bin/zsh your_user