devblog

Intermediate
  • Async/Await
  • API
  • JSON
  • axios
  • React
  • #2PlaysAMonth
avatar
AmrinFeb 19, 2023
A dev to client. Read dev to blog in a new frontend
Why Oh My ZSH is so cool?

Why Oh My ZSH is so cool?

#productivity
#zsh
#terminal
#tooling

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

  • Globbing

CommandResult
ls *.txtlist all txt files in the current directory
ls **/*.txtlist 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
CommandResult
touch name-{1..4}.txtcreate 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.jsview 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}.jpgdownload multiple files
  • Expand environment variables $ENV followed by TAB

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

segmentmeaning
mastercurrent branch
#v1HEAD is tagged with v1; not shown when on a branch
@5fc6fca4current commit; not shown when on a branch or tag
⇣1local branch is behind the remote by 1 commit
⇡2local branch is ahead of the remote by 2 commits
⇠3local branch is behind the push remote by 3 commits
⇢4local branch is ahead of the push remote by 4 commits
*5there are 5 stashes
mergemerge is in progress (could be some other action)
~6there are 6 merge conflicts
+7there are 7 staged changes
!8there are 8 unstaged changes
?9there 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