There is a before and after listening to these letters together: ZSH. You may wonder: Why did not I hear about this before? D'oh!
ZSH (Z Shell) it's a real evolution, modernize terminal things with simple solutions. But the thing getting better when you discover Oh My ZSH! a framework for ZSH that boost your productivity and improve your workflow.
So, why?
- No more
cd
(change directory) command. Just use:
Command | Result |
---|---|
folder/ |
write the folder name with / at the end |
.. |
go back one folder (parent dir) |
... |
go back two folders (parent from parent dir) |
...... |
go back five folders |
/ |
go to root |
~ |
go to home |
- |
jump to previous path |
Recursive path expansion.
/u/lo/b
expands to/user/local/bin
Spelling correction and approximate completion, automatic correct when having minor mistake typing a directory name
take
the 3 in 1 command who create a directory and automatically change the path to it
Command | Result |
---|---|
take <url_file> |
Download gzip file (.gz , .bz2 , .xz ) and uncompress |
take <git_repo> |
Clone git repo from url (http , ssh ) |
take <folder> |
Create a new folder |
zsh_stats
will give you a list of the top 20 commands and how many times they've been runTab completion is another great feature. For example, typing
ls -
and pressingTAB
will list all of the command's options, along with a helpful description of what they doAlias commands. List all with
alias
or filter it withgrep
for examplealias | grep git
Globbing
Command | Result |
---|---|
ls *.txt |
list all txt files in the current directory |
ls **/*.txt |
list all txt files including subdirectories |
ls **/(READ)*.* |
find for files that start with the word READ
|
ls **/*(READ).* |
find for files that end with the word READ
|
ls **/*(READ)*.* |
find for files that have the word READ anywhere |
ls **/*(.) |
search for files only |
ls **/*(/) |
search for folders only |
- Expanding File Names and Directories
Command | Result |
---|---|
touch name-{1..4}.txt |
create files name-1.txt , name-2.txt , name-3.txt , name-4.txt
|
touch name.{css,js,test.js} |
create files with different extension name.css , name.js , name.test.js
|
cp folder/name.js{,.bak} |
create a copy of the file ending .bak
|
diff folder/{new,old}/name.js |
view differences between two files |
mkdir -p {source,build,man,help{/pages,/yelp,/images}} |
create a complete folder structure |
wget http://site.com/folder{1,2}/pic{001,002}.jpg |
download multiple files |
Expand environment variables
$ENV
followed byTAB
Expand
kill
command followed byTAB
History substring search writing a command and pressing the up arrow cycles through previous usages
Autocomplete, jump between options with tab, and press return for selection. Works with directories, files, and commands
Run history command with
!
followed by the number in history, like!137
Entering
!!
will bring up the last command. This is handy if a command fails because it needs admin rights. In this case you can typesudo !!
Plugins
There are a lot of plugins to use. It's recommended to explore the options and use what is good for your needs.
My recommendations are:
- sudo to easily prefix your current or previous commands with sudo by pressing esc twice
- command-not-found to provide suggested packages to be installed if a command cannot be found
- extract that extracts the archive file you pass it, and it supports a wide variety of archive filetypes
- git provides many aliases and a few useful functions
- history-substring-search a clean-room implementation of the Fish shell's history search feature, where you can type in any part of any command from history and then press chosen keys, such as the UP and DOWN arrows, to cycle through matches
- web-search adds aliases for searching with Google, Wiki, Bing, YouTube and other popular services
- z command that tracks your most visited directories and allows you to access them with very few keystrokes
I've another extra from plugins from external repositories to add more functionalities:
- autosuggestions suggests commands as you type based on history and completions.
- syntax-highlighting Fish shell-like syntax highlighting for ZSH
- ohmyzsh-full-autoupdate Automatic update of custom plugins and themes Oh My Zsh
Themes
There are also a lot of themes, but my favorite is Powerlevel10k because is easy to set up and use
Git
Incredible and complete aliases for Git
Git Status Prompt can contain the following bits:
segment | meaning |
---|---|
master |
current branch |
#v1 |
HEAD is tagged with v1 ; not shown when on a branch |
@5fc6fca4 |
current commit; not shown when on a branch or tag |
⇣1 |
local branch is behind the remote by 1 commit |
⇡2 |
local branch is ahead of the remote by 2 commits |
⇠3 |
local branch is behind the push remote by 3 commits |
⇢4 |
local branch is ahead of the push remote by 4 commits |
*5 |
there are 5 stashes |
merge |
merge is in progress (could be some other action) |
~6 |
there are 6 merge conflicts |
+7 |
there are 7 staged changes |
!8 |
there are 8 unstaged changes |
?9 |
there are 9 untracked files |
Shortcuts
Edit long command
ctrl+x+e
open the command on an editor to easy edit, once save and close the editor it will be updated on the terminal
You can set your favorite editor, for example run export EDITOR="code -w"
to use VSCode
Park a command
ctrl+q
"parks" the command you're currently typing and takes you back to the prompt, letting you start over and type another command. Once you run that other command, the original command is un-parked and refills the command line so you can continue.
This is good for if you, say, forgot to do a command before a command.
Reveal alias
ctrl+x
a
will transform the alias to the real command
Path history
ZSH keeps the history of directories you visited so you can quickly switch to any of them.
To see the list, type dirs -v
. Switch to any directory in this list by typing ~#
where #
is the number of the directory in the list.
Hooks
You can personalize actions (before and after a command) with ZSH Hooks
Reveal the command behind an alias with ZSH
Camilo Martinez ・ Feb 22 '21
That's All Folks!
Happy Coding 🖖
Sources