DEV Community

What is the best .zshrc config you have seen?

Manan Joshi on November 12, 2019

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 #C...
Collapse
 
tommykolkman profile image
Tommy Kolkman

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

sourceZsh(){
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."
}

editZsh(){
    nano ~/.zshrc
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."
}

backupToDrive(){
    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.

Collapse
 
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.

Collapse
 
b2aff6009 profile image
b2aff6009

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
}

sourceZsh(){
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."
}

editZsh(){
    updateYadm
    vim ~/.zshrc
    source ~/.zshrc
    backupToDrive ~/.zshrc
    echo "New .zshrc sourced."
}

updateYadm() {
    yadm pull
}

backupToDrive(){
    yadm add ~/.zshrc
    yadm commit -m "updated .zshrc"
    yadm push
    echo "New .zshrc backed up to yadm."
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
alexisfinn profile image
AlexisFinn

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!!

Collapse
 
tommykolkman profile image
Tommy Kolkman

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

Collapse
 
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.

Collapse
 
manan30 profile image
Manan Joshi

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

Collapse
 
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.

Collapse
 
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.

Collapse
 
mjsarfatti profile image
Manuele J Sarfatti

I love your react-app shortcut!

Collapse
 
manan30 profile image
Manan Joshi

Thanks a lot

Collapse
 
romkatv profile image
Roman Perepelitsa

FYI: There is powerlevel10k now.

Collapse
 
alexisfinn profile image
AlexisFinn

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.

Collapse
 
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
AlexisFinn

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.

Collapse
 
lbeul profile image
Louis

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

Collapse
 
manan30 profile image
Manan Joshi

Sure Louis here it is.
iTerm.png