📜 ⬆️ ⬇️

Ansible: configure a zsh terminal with antigen, autosuggestions, fzf and a beautiful prompt with one command

I spend a lot of time in the terminal, so I want everything to be beautiful, fast and convenient. From this comes the constant desire to customize it, try different plugins. I chose Shell for myself 5 years ago, zsh, I found oh-my-zsh for its convenient configuration a couple of years ago.


Over time, some configuration of the side of the protruding parts in the form of powerline and percol.


Recently, I decided to rebuild everything in order to get rid of unnecessary plug-ins, add the necessary ones, make an easy installation and update. As a result, the role of ansible-role-zsh appeared , which completely configures the terminals on LAN and on my servers.


Features:



Demonstration of features for 1 minute:





I used to use powerline , which was responsible for the command prompt (status bar) and percol for interactive search. Both utilities are written in python.


They are good when I found percol, the speed of work in the terminal immediately grew, I was happy about it on the blog , but it was not all very nicely put (bash installer), had some problems when working with several users with beautiful terminals on the same server.


Also, in some cases, the disadvantages of utilities were manifested: the terminal was loaded with a slight delay (about 1 second), percol stumbled on large amounts of text.


Python utilities wanted me to set them up through separate configs. I didn’t want to support separate configs, so I used them with the default settings, and I wouldn’t say that they were bad, but it could have been better.


For these reasons, I looked for what they can be replaced and found.


fzf, Percol replacement


Fuzzy finder is written in Go, has a bunch of asterisks, judging by the description, sharpened to work in Vim, but also works in other places.


When choosing, I also looked at peco , they are similar, both are written by some Japanese on Go, I chose fzf according to the following criteria:



Fzf has a kind of cool feature for autocompleting different things through **<Tab> , I didn’t check, but the author of the plugin fzf-zsh writes that it conflicts with zsh-autosuggestions , I believe him.


Powerlevel9k, Powerline replacement


I found the powerlevel9k topic by chance, then checked it on request on the Github powerline zsh it is second (after the powerline itself).


The theme is sophisticated, it allows a lot of things, I used some of the features:



Like powerline, the theme requires installing patched powerline fonts , I use Droid Sans Mono, 12pt. The font and color scheme are two things that need to be set manually.


zsh-autosuggestions


The discovery of this plugin for me is comparable to the discovery of percol: the speed of command set has increased.
It is often necessary to type a command with the same parameters as last time, or with some other parameters. The plugin helps out in both cases.


It works like this: when you enter a command, the plugin reads the history and gray-writes the last command from the history, starting the same way.


If you press Enter, your command will be executed, and not from auto-completion (this is good, it will be difficult to accidentally call the wrong command, although some auto-completions have such problems). To substitute an augmented command, you need to click the button that is assigned to the autosuggest-accept action, the default is →.


But until the arrow to the right is constantly uncomfortable, so I first zabindil autocompletion on the backtick (backward quote, which is to the left of the unit). It was very convenient: right next to Tab and it works like a Tab . But later it turned out that this breaks down the work of Midnight Commander: on some systems he stopped switching the path in the internal shell (which is useful: go to the right folder via mc, press Ctrl+O , enter the command, exit the internal shell, or vice versa it is more convenient to go into the folder through the shell, and then perform actions in mc), on other systems mc generally hung after a couple of transitions to folders. I googled the problem, the mc tracker has such a glitch, in the latest version 4.8.18 hangs were removed, but the path did not change, so I began to try other hot keys: Ctrl+Space , Ctrl+I , all of them were somehow buggy.


As a result, I came to this: I rarely use mc, so on all systems, where I am not only, I bind to Ctrl+U , and on personal systems - also to a quotation mark. In the playbook, only the arrow is jammed.


Even in ansible-role-zsh, the plug-in's work is limited to 15 characters, that is, after 15 characters it stops offering commands.


This is done in order to remove delays when copying commands into the terminal (I do not feel any delays when I enter them myself, but when inserting large commands from the buffer, it is noticeable, as if the insertion did not work).


zsh-syntax-highlighting


About this plugin you can say not very much: highlights the current command entered, coloring on the fly.


The main advantage is that you see that the words were sealed by the red color. I will not say that it is a must have, but it becomes more convenient.


At the same time, the plugin has several jambs at once.


On systems where zsh < 4.3.17 , causes the terminal session to crash, so the playbook has protection against plug-in activation on such systems. A rare case, I did it for the sake of Debian Squeeze.


The plugin should be connected last, but I don’t know what will happen and don’t want to know.


Conflicts with zsh-autosuggestions, manifested in the session crash when trying to reapply the .zshrc config.


There is a corresponding issue about this and the author of zsh-autosuggestions says that the fix is ​​already in the devel branch, I did not check, but if so, after the release of v0.3.4 everything should be fixed.


In the playbook there is a fix for this, so the conflict is resolved.


zsh-command-time


While putting things in order in this project, he implemented one of his long-time likes: the output of execution time for commands that take a long time to complete. Before that, I either looked at the clock in the right corner of the terminal and compared it with the clock in the previous command, or I immediately ran the command with time . Now this is not necessary.


Appearance of the theme in different color schemes


I use the Solarized Dark color scheme, but in order not to upset my colleagues who go to the servers I set up, I checked how the terminal looks on the standard Putty palette on the standard Ubuntu palette on the iTerm built-in themes:





Installation


So, if you like it, I suggest you first see the work live, in Vagrant:


 git clone https://github.com/viasite-ansible/ansible-role-zsh.git vagrant up 

Before installing on a working system, carefully read this:



If everything suits you, you can install the role via ansible-galaxy :


 ansible-galaxy install viasite-ansible.zsh 

Then create a playbook like this:


 hosts: all vars: zsh_autosuggestions_bind_key: "^U" roles: - viasite-ansible.zsh 

Save, for example, in zsh.yml . After that, the role can be applied to the local user:


 ansible-playbook -i "localhost," -c local zsh.yml 

How to apply to other users and servers ansible users think I will understand.


Tested on Debian 6, Ubuntu 14.04, Ubuntu 16.04, macOS 10.12, CentOS 7.


All available variables did not make in README.md, they can be viewed
in defaults / main.yml .


findings


I understand that the terminal configuration is a very personal thing, I’m not sure that there will be many people who want to take advantage of my ansible role, so I tried to make it as customizable as possible. If will be willing to use, please leave issues.


Of course, this is not the last config, for example, while I was writing this article, I found antigen , a plug-in manager for zsh, which is written similarly to Vundle for Vim, sharpened to work in conjunction with oh-my-zsh and eliminates the manual installation of plug-ins . This is just one of the problems that I solved by writing a role. Share who enjoyed.
UPD 04/03/2017: rewrote the role using antigen.


In the comments I would like to find new tasty plug-ins, please write, what plug-ins caused you to feel "how have I lived without it before?"


UPD: added CentOS support, thanks, BeeVee !


')

Source: https://habr.com/ru/post/323496/


All Articles