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.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.
Overall, starship allows you to configure many extensions in the command window. The example below is my command line window after some configuration.
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 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 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?
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.
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
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.
Me & the desire to "play with words"
Have you tried writing? And then failed or not satisfied? At 2coffee.dev we have had a hard time with writing. Don't be discouraged, because now we have a way to help you. Click to become a member now!
Subscribe to receive new article notifications
Comments (0)