Why Oh My ZSH is so cool?

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 y…


This content originally appeared on DEV Community and was authored by Camilo Martinez

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.

cool bro

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
  • take the 3 in 1 command who create a directory and automatically change the path to it
Command Result
take <file> Download gzip file (.gz, .bz2, .xz) and uncompress
take <git_repo> Clone git repo from url (httl, ssh)
take <folder> Create a new folder
  • Jump between last and current path with - (like a TV remote control)

  • zsh_stats will give you a list of the top 20 commands and how many times they've been run

  • Tab completion is another great feature. For example, typing ls - and pressing TAB will list all of the command's options, along with a helpful description of what they do

  • Alias commands. List all with alias or filter it with grep for example alias | grep git

  • With globbing (a Zsh feature), you can list files with a particular extension. For example, ls *.html will list all HTML files in the current directory. To include subdirectories, change to: ls **/*.html

  • 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

  • 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 type sudo !!

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
  • 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:

Themes

There are also a lot of themes, but my favorite is Powerlevel10k because is easy to set up and use

p10k

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

Sources

That’s All Folks!
Happy Coding 🖖

beer


This content originally appeared on DEV Community and was authored by Camilo Martinez


Print Share Comment Cite Upload Translate Updates
APA

Camilo Martinez | Sciencx (2023-03-04T00:37:11+00:00) Why Oh My ZSH is so cool?. Retrieved from https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/

MLA
" » Why Oh My ZSH is so cool?." Camilo Martinez | Sciencx - Saturday March 4, 2023, https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/
HARVARD
Camilo Martinez | Sciencx Saturday March 4, 2023 » Why Oh My ZSH is so cool?., viewed ,<https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/>
VANCOUVER
Camilo Martinez | Sciencx - » Why Oh My ZSH is so cool?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/
CHICAGO
" » Why Oh My ZSH is so cool?." Camilo Martinez | Sciencx - Accessed . https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/
IEEE
" » Why Oh My ZSH is so cool?." Camilo Martinez | Sciencx [Online]. Available: https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/. [Accessed: ]
rf:citation
» Why Oh My ZSH is so cool? | Camilo Martinez | Sciencx | https://www.scien.cx/2023/03/04/why-oh-my-zsh-is-so-cool/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.