DEV Community

Manan Joshi
Manan Joshi

Posted on

What is the best .zshrc config you have seen?

I was editing my .zshrc the other day and wondered what cool things people are doing with it.

Here's my config

# Created by manan for 4.4.2

#Customise the Powerlevel9k prompts

# Options for setting colors to directories.


# Load Nerd Fonts with Powerlevel9k theme for Zsh
source  ~/Spaces/Editor-Settings/powerlevel9k/powerlevel9k.zsh-theme

source "$HOMEBREW_FOLDER/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
source "$HOMEBREW_FOLDER/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$HOMEBREW_FOLDER/zsh-history-substring-search/zsh-history-substring-search.zsh"

autoload -Uz compinit;
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
  compinit -i
  compinit -C -i

zmodload -i zsh/complist

#History setup

setopt hist_ignore_all_dups # remove older duplicate entries from history
setopt hist_reduce_blanks # remove superfluous blanks from history items
setopt inc_append_history # save history entries as soon as they are entered
setopt share_history # share history between different instances of the shell
setopt auto_cd # cd by typing directory name if it's not a command
setopt correct_all # autocorrect commands
setopt auto_list # automatically list choices on ambiguous completion
setopt auto_menu # automatically use menu completion
setopt always_to_end # move cursor to end if word had one match

zstyle ':completion:*' menu select # select completions with arrow keys
zstyle ':completion:*' group-name '' # group results by category
zstyle ':completion:::::' completer _expand _complete _ignored _approximate #enable approximate matches for completion

#Plugins setup
source <(antibody init)
antibody bundle zdharma/fast-syntax-highlighting > ~/.zshrc.log
antibody bundle zsh-users/zsh-autosuggestions > ~/.zshrc.log
antibody bundle zsh-users/zsh-history-substring-search > ~/.zshrc.log
antibody bundle zsh-users/zsh-completions > ~/.zshrc.log
antibody bundle /Users/manan/Spaces/Editor-Settings/ZSH-Plugins/oh-my-zsh-master/plugins/osx > ~/.zshrc.log
# antibody bundle robbyrussell/oh-my-zsh path:plugins/heroku > ~/.zshrc.log
antibody bundle robbyrussell/oh-my-zsh path:plugins/node > ~/.zshrc.log
antibody bundle robbyrussell/oh-my-zsh path:plugins/web-search > ~/.zshrc.log
antibody bundle robbyrussell/oh-my-zsh path:plugins/sudo > ~/.zshrc.log
antibody bundle robbyrussell/oh-my-zsh path:plugins/react-native > ~/.zshrc.log
# antibody bundle robbyrussell/oh-my-zsh path:plugins/kubectl > ~/.zshrc.log
# antibody bundle robbyrussell/oh-my-zsh path:plugins/npm > ~/.zshrc.log
antibody bundle JamesKovacs/zsh_completions_mongodb > ~/.zshrc.log
source /usr/local/aws/bin/

autoload -Uz compinit;compinit -i

# Aliases

alias grep=ack
alias digitalocean="ssh digitalocean"
alias ls="colorls"
alias python="python3"
alias pip="pip3"
alias easy-install="easy_install-3.7"
alias config="vi $HOME/.zshrc"
alias projects="cd $HOME/Spaces/Projects"
alias reload="source $HOME/.zshrc"

# Git aliases
alias gi="git init"
alias gs="git status -sbu"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gp="git push"
alias gm="git merge"
alias ga="git add ."
alias gcm="git commit -m"
alias gpl="git pull"
alias gst="git stash"
alias gstl="git stash list"
alias glg='git log --graph --oneline --decorate --all'

# Exports
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-toolsz

export GOPATH=/Users/manan/.golib
export PATH=$GOPATH/src:$PATH
export GOPATH=$GOPATH:/Users/manan/Spaces/Projects/Go

export PATH="/usr/local/opt/libpcap/bin:$PATH"

fpath=(/usr/local/share/zsh-completions $fpath)
export PATH="/usr/local/opt/icu4c/bin:$PATH"
export PATH="/usr/local/opt/icu4c/sbin:$PATH"

export PYTHON3PATH=/Library/Frameworks/Python.framework/Versions/3.7

export PATH=/usr/local/aws/bin:$PATH

export PATH=$PATH:$HOME/sdk/flutter/bin

# added by travis gem
[ -f /Users/manan/.travis/ ] && source /Users/manan/.travis/

# Misc
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

# Tab title
precmd() {
  # sets the tab title to current dir
  echo -ne "\e]1;${PWD##*/}\a"

# Create a new react app

react-app() {
  npx create-react-app $1
  cd $1
  npm i -D eslint
  npm i -D eslint-config-prettier eslint-plugin-prettier
  npm i -D eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks
  cp "${HOME}/.eslintrc.json" .
  cp "${HOME}/.prettierrc" .
  echo $1 >
  rm -rf yarn.lock
  cd src
  rm -f App.css App.test.js index.css logo.svg serviceWorker.js
  mkdir components views 
  git add -A
  git commit -m "Initial commit."
  cd ..
  code .
Enter fullscreen mode Exit fullscreen mode

Feel free to show your .bashrc or any other configs that you have. You can find my collection here.

Find me on Twitter and Instagram

Top comments (19)

tommykolkman profile image
Tommy Kolkman

I've always liked adding this little snippet to my .zshrc:

    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."

    nano ~/.zshrc
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."

    cp "$1" /Users/<username>/Google\ Drive/Config/.zshrc
    echo "New .zshrc backed up to Google Drive."
Enter fullscreen mode Exit fullscreen mode

So just use editZsh to edit your .zshrc and it will be safe!

When switching machines, I only have to get my .zshrc from the Drive and here we go again.

manan30 profile image
Manan Joshi

Hey Tommy, I actually use yadm to manage my dotfiles. They are then pushed on to GitHub here. So whenever I want to set up a new machine the only thing I need to do is just clone that repo.

b2aff6009 profile image

Thanks for sharing. I improved my .zshrc a lot since I saw this post. As I use my .zshrc on different machines I implemented an update before the edit.
And as I search for quite often for some strings inside of files I wrote a "find in files" function

alias findr='\fd'
#function for find strings in files
fif() {
    findr --type f $1|xargs grep -n -i  $2

    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."

    vim ~/.zshrc
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."

updateYadm() {
    yadm pull

    yadm add ~/.zshrc
    yadm commit -m "updated .zshrc"
    yadm push
    echo "New .zshrc backed up to yadm."
Enter fullscreen mode Exit fullscreen mode
alexisfinn profile image

Nice, I usually just version my entire Home directory, the process being to first add a .gitignore with * so that by default everything is ignored, and then I can force-add whatever I want to version (remember gitignore doesn't apply to anything that is already versioned).
That way I can also version my fonts folder, background-images folder and whatnot.

Thread Thread
luismartinezs profile image
Luis Martinez Suarez

Duh.... that is a great idea!!

tommykolkman profile image
Tommy Kolkman

D'oh! I should've known something like this exists - I'm gonna dive into that, thanks!

vonheikemen profile image
Heiker • Edited

I think most people just install oh-my-zsh and forget about .zshrc. Is what I did at first. So I think the first place to look is the oh-my-zsh repository, they have some really useful stuff in the plugins folder.

This are my favorite.

# Use - to go back to previous directory
alias -- -='cd -'

# Taken from the tmux plugin
alias ta="tmux attach -t"
alias ts="tmux new-session -s"
alias tl="tmux list-sessions"

# Keybindings

autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search

# [Space] - do history expansion
bindkey ' ' magic-space

# start typing + [Up-Arrow] - fuzzy find history forward
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search

# start typing + [Down-Arrow] - fuzzy find history backward
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
Enter fullscreen mode Exit fullscreen mode

They do a little bit of magic in another file to make sure terminfo has a value.

I actually uninstalled oh-my-zsh and kept what I needed. The zsh specific stuff is here. And what is (mostly) POSIX compliant is here.

manan30 profile image
Manan Joshi

I 100% agree with this I think most people just install oh-my-zsh and forget about .zshrc.

sikloidz profile image
José Landero

I was one of those until today, I'd never thought about how handy could be to have some aliases here and there

Thread Thread
manan30 profile image
Manan Joshi

I am not 100% certain if aliasing actually saves some time but it sure does save you some keyboard clicks.

gergelypolonkai profile image
Gergely Polonkai

I use fish.

But before i switched, i used a plain oh-my-zsh with some plugins made by myself. I really liked it, and occasionally miss it. However, despite a few quirks, i don’t regret switching to fish for my interactive sessions; scripting is still better in good old bash or, if portability is a must, plain sh.

mjsarfatti profile image
Manuele J Sarfatti

I love your react-app shortcut!

manan30 profile image
Manan Joshi

Thanks a lot

romkatv profile image
Roman Perepelitsa

FYI: There is powerlevel10k now.

alexisfinn profile image

Nice, but why ? The project says it's a drop-in replacement for powerlevel9k but then why not just use the original ? It's still active as far as I know so is there some sort of issue why I would want to use the replacement ?
This is an honest question, and if the answer turns out to be why-not, well I'm down with that answer as well, after all that's the beauty of open-source.

romkatv profile image
Roman Perepelitsa

The project says it's a drop-in replacement for powerlevel9k

Not quite. Here's what it says:

Powerlevel10k can be used as a fast drop-in replacement for Powerlevel9k.

  • Fast: Powerlevel10k is over 10 times faster than powerlevel9k when using the same configuration options.
  • Can be used as a drop-in replacement rater than is a drop-in replacement: Powerlevel10k has many extra features not found in Powerlevel9k.

[powerlevel9k is] still active as far as I know

I guess this depends on one's point of view. Commit activity graph shows last commit in March.

Thread Thread
alexisfinn profile image

Cool. Thanks for the quick reply and insight on the differences between the two projects.
I'm quite a sucker for 'fast' and lightweight, so now I'm going to have to try it.

lbeul profile image

It would be very cool to see what your terminal looks like! Could you attach a screenshot that shows the result of your configs?

manan30 profile image
Manan Joshi

Sure Louis here it is.