Search code examples
zshoh-my-zshzshrc

Revert .zshrc file to its previous state


I accidentally override .zshrc. The file is now empty. Fyi, I still have one terminal (macos) which loaded its previous configuration. Is it possible to revert it back?


Solution

  • One possible solution to avoid future mistakes, if you are using vim with its proper undo settings you can get back in time:

    " Reference: https://vi.stackexchange.com/a/53/7339
    " Let's save undo info!
    if !isdirectory($HOME."/.vim")
        call mkdir($HOME."/.vim", "", 0770)
    endif
    if !isdirectory($HOME."/.vim/undo-dir")
        call mkdir($HOME."/.vim/undo-dir", "", 0700)
    endif
    set undodir=~/.vim/undo-dir
    set undofile
    

    Then you can run the :earlier command, like this:

    :earlier 1d
    

    For more about this run :h earlier

    A second solution is to create a git repo with your "dotfiles" and then creating symlinks, like:

    ln -sfvn ~/.dotfiles/zshrc ~/.zshrc