DEV Community

Discussion on: What is the best .zshrc config you have seen?

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 Author

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
tommykolkman profile image
Tommy Kolkman

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

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