About zsh more than once wrote on Habré. However, both those topics and my personal observations show that most people familiar with zsh use it as a bash with advanced autocomplete. And that (autocomputer) is not used to its fullest.
I do not want to describe how to paint the console in all the colors of the rainbow or make promt, showing everything. I want to show that zsh's capabilities are much broader, and using it as the main shell can make your work a little more beautiful.
In zsh, they are of four types:
About the first two types were written more than once. The last two are more interesting.
alias -gg="| grep" alias -gl="| less"
cat where | grep what | less
do cat where g what l
Without specifying a flag when creating an alias, it behaves as both standard and global. But I recommend specifying a flag to avoid ambiguities.
Aliases can be temporarily turned off / on by
disable -a aliasname enable -a aliasname
\aliasname #or =aliasname
hash -d apl=/private/var/log/apache2 hash -d p1=/srv/www/project1/html
cd ~hashname
or at all ~hashname
if you use the autocd option.
Of course, hashes can be used in any other operations related to file paths:
cat ~hashname/file cp ~hashname/file /path/somewhere
He is really powerful in zsh .
In addition to being able to complement the options of many commands (and it’s easy to write your own complement), zsh allows you to twist it as you please:
zstyle ':completion:*:processes' command 'ps -ax' zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;32' zstyle ':completion:*:*:kill:*' menu yes select zstyle ':completion:*:kill:*' force-list always zstyle ':completion:*:processes-names' command 'ps -e -o comm=' zstyle ':completion:*:*:killall:*' menu yes select zstyle ':completion:*:killall:*' force-list always
This config will give us a complement for the kill and killall commands:
DevMan% killall F Finder ForkLift
DevMan% kill Sa 502 ?? 2:49.10 /Applications/Safari.app/Contents/MacOS/Safari -psn_0_53261 823 ?? 14:29.44 /System/Library/StagedFrameworks/Safari/WebKit2.... 1509 ?? 4:28.21 /Applications/Xmarks for Safari.app...
Deciding whether to use a case-insensitive complex I leave to you. Although I personally get from him a lot more good than harm.
Hooks are functions that are called upon a specific event.
I actively use 3 of them:
The first one I use to restore all consoles in those directories in which I was before the reboot / logout.
I use the second and third hooks, in particular, to notify about processes running for longer than a specified time: I started the project build, for example, and switched to other tasks when the build ends in the notification center when the readiness notification arrives.
ls *(.) # ls *(.om[1]) # ls -l *(.m0) # ls **/style.css # style.css ls -l *(.Lk+50) # 50 ls **/*(.Lm+5) # 5 ls *.^log # , .log vi *(.om[1]) # # setopt EXTENDED_GLOB
This is an insignificant example of what zsh is capable of.
Not affected modules, which is enough.
As a teaching tool, in addition to native mans and guide, I recommend to study
If the topic is interesting, we will continue.
Enjoy all the coding!
Source: https://habr.com/ru/post/164597/