Migrating Off Oh-My-Zsh

Migrating Off Oh-My-Zsh

Daily short news for you
  • These past few days, I've been redesigning the interface for the note-taking app OpenNotas. It's quite strange to think about why I chose DaisyUI back then 😩

    » Read more
  • Previously, there was a mention of openai/codex - a type of agent that runs conveniently in the Terminal from OpenAI, especially since it is open source and they have now added support for other providers instead of just using the chatgpt model as before.

    Recently, Anthropic also introduced Claude Code which is quite similar to Codex, except it is not open source and you are required to use their API. Since I don't have money to experiment, I've only heard that people in the programming community praise it a lot, and it might even be better than Cursor. On the flip side, there's the risk of burning a hole in your wallet at any moment 😨

    » Read more
  • For a long time, I have been thinking about how to increase brand presence, as well as users for the blog. After much contemplation, it seems the only way is to share on social media or hope they seek it out, until...

    Wearing this shirt means no more worries about traffic jams, the more crowded it gets, the more fun it is because hundreds of eyes are watching 🤓

    (It really works, you know 🤭)

    » Read more

The Issue

Hello readers of 2coffee.dev, as shared in a post in the Threads section, I recently had quite an interesting experience of "migrating" off oh-my-zsh. If you remember, you will see that I have a post titled The story of transitioning from Windows to Linux/Unix - thanks to zsh and oh-my-zsh, which is proof of how much I enjoy using the command line.

Typing commands is a regular task, so I always look for ways to optimize or type commands quickly and easily. If there's a cool tool, I jump in to learn how to use it. The article Migrating Off Oh-My-Zsh and other recent Yak Shavings was like a spark that accidentally hit the oil slick. It's time to find out why the author left this wonderful tool?

Revisiting oh-my-zsh, I realized that I didn't actually use many of its features. Oh-my-zsh was created a long time ago; back then, it was a worthwhile choice, but at this moment, with the rapid development of open-source applications, many newer, faster, and more flexible names have emerged.

Therefore, in this article, I will try to follow what the author of the above article suggested. Let's see if this migration is worthwhile.

First, let's uninstall oh-my-zsh. Open the .zshrc file and delete the line source $ZSH/oh-my-zsh.sh. Then delete the ~/.oh-my-zsh directory.

rm -rf ~/.oh-my-zsh  

Let's get started!

starship

starship.rs is a utility tool that helps customize the shell, supporting many shells, including zsh. Written in Rust, it brings speed and reliability.

Installing starship is very simple. Here I use Mac, installing via Homebrew.

brew install starship  

If you use a different operating system, refer to the installation instructions at Starship Installing

Since I'm using zsh, I add this line to the end of the ~/.zshrc file

eval "$(starship init zsh)"  

Starship supports many shells, so for more information, refer to Setup Shell

After completing, reload the configuration by typing source ~/.zshrc, and you will see the new interface.

Default interface

Overall, starship allows you to configure many extensions in the command window. The example below is my command line window after some configuration.

Customized interface

And here is the configuration file.

# ~/.config/starship.toml  

"$schema" = 'https://starship.rs/config-schema.json'  

add_newline = false  

# Replace the '❯' symbol in the prompt with '➜'  
[character] # The name of the module we are configuring is 'character'  
success_symbol = '[➜](bold green)' # The 'success_symbol' segment is being set to '➜' with the color 'bold green'  

[hostname]  
ssh_only = true  
format = '[$ssh_symbol$hostname]($style) '  
ssh_symbol = "@"  
style = "yellow"  

[username]  
disabled = false  
show_always = true  
format = '😨 [$user]($style) '  
style_user = "yellow"  

[directory]  
truncation_length = 4  
truncate_to_repo = false  

[git_branch]  
truncation_length = 20  
# remove the 'on' conjunction  
# format = '[$symbol$branch]($style) '  

[git_state]  
disabled = true  

[git_status]  
disabled = true  

[memory_usage]  
disabled = true  
format = '$symbol [${ram}]($style) '  
threshold = -1  
symbol = " "  
style = "bold dimmed green"  

[time]  
disabled = false  
format = '🕙 [$time]($style) '  
time_format = '%T'  

[nodejs]  
disabled = true  

In addition, there are many settings for languages and tools that you can find at Config. The remaining task is to find out what it allows you to display and then add it to the configuration file.

fzf

fzf is a versatile fuzzy finder tool. It is written in C, providing impressive search speed. But wait, why do we need a search tool here?

Actually, it helps you find everything on your computer. For example, you can find any file or directory in the system. Or a very frequently used application of mine is to look back at the command history used in the system.

fzf supports many platforms; here I install it via brew

brew install fzf  

Open ~/.zshrc, add this line at the end

# Set up fzf key bindings and fuzzy completion  
source <(fzf --zsh)  

Can't figure out how to use it? Try typing fzf. Immediately, the tool will scan all files on the computer and be ready for searching.

Or use it to search based on the output of another command, in a pipe format.

ls -lh | fzf  

Now search command history by pressing Ctrl + R. Type in a few characters and press Enter.

zoxide

zoxide is a utility that replaces the traditional cd command; it has the ability to "remember" the paths you have navigated to and then move quickly to that directory with a simple command.

Install zoxide.

brew install zoxide  

Add this line to the end of ~/.zshrc

eval "$(zoxide init zsh)"  

Usage is very simple; instead of using cd, use z.

z src/hoaitx/2coffee-next/page  
z ~/src/hoaitx/2coffee-next/api  

The interesting thing is that after that, if you want to navigate to the page directory, you just need to type:

z page  

Saves a lot of time navigating, right?

Some Other Plugins

Search history

After uninstalling oh-my-zsh, I realized that one feature I frequently used was pressing the up/down arrow keys to quickly find command history. For example, if you typed many docker commands and just wanted to find commands starting with docker run, you would type docker run and press the arrow keys, and it would suggest all commands starting with those two words.

In zsh, there is a plugin called zsh-history-substring-search that can do this.

Installation.

brew install zsh-history-substring-search  

Add these lines to the end of the ~/.zshrc file

# search history substring search  
source ~/.zsh/zsh-history-substring-search/zsh-history-substring-search.zsh  
bindkey '^[[A' history-substring-search-up  
bindkey '^[[B' history-substring-search-down  

The two bindkey lines are for the up and down arrow keys to navigate the search.

Auto suggestion

zsh-autosuggestions is a plugin that suggests commands based on history. Imagine typing a few characters, and it finds and suggests the next command based on what you have typed before. Then you just need to press tab...

Installation.

brew install zsh-autosuggestions  

Add this line to the end of the ~/.zshrc file

source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh  

Conclusion

Above are all my new installations after leaving oh-my-zsh. This can be considered a new beginning for optimizing my shell. If I find new "toys," I will continue to update in this article.

What about you? What tools are you using to refresh your shell? Please leave a comment below the article to let me and everyone else know. Thank you.

Premium
Hello

5 profound lessons

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (0)

Leave a comment...