3

Scenario: I want my Zsh and Oh-My-Zsh setup to be the same across my personal Mac, my work Mac, my Linux Desktop, my raspberry pis.

Each of these have different usernames (and even different paths to their home directory /Users/MyUserName for Mac and /home/MyUserName for Linux.

I tried creating a git repo for my .zshrc and created some basic scripts that git pull all my plugins but the problems arose when i tried to install on a new raspberry pi and noticed that the path to my home directory depended on my system and .oh-my-zsh install script uses the ZSH environmental variable to install itself. This meant that i needed to create a pre-oh-my-zsh .zshrc that detected the system with uname -s and set the prefix for the ZSH variable appropriately.

Unfortunately .oh-my-zsh just overwrites this so whenever I would want to make edits to my config and push it the git repo i'll have to re-install each time. It seems like there must be a solution.

How do I make it so my zsh dotfiles are agnostic to my machine environment and my username for paths so that I can install .oh-my-zsh and make updates to my dotfiles that I can propagate to my other machines?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Taako
  • 587
  • 2
  • 6
  • 21
  • I think you have to create a list of what exactly is different between the systems. You just gave examples. The home directory provides the least problems, because you can get its name from '$HOME' . Can you tell oh-my-zsh to write its settings always to a completely unrelated file, which you then can source from your dot-files? I have not played with oh-my-zsh for a while, but when I did, I don't remember that they would destroy or change things I don't want to be changed. – user1934428 May 29 '20 at 07:54

2 Answers2

1

I would recommend keeping your config dotfiles in a single git config repo but then creating symlinks to where they ought to live on your machine. Properties of symlinks are such that they are more maintainable than copying and pasting configs around.

They allow updates to be made either in the config-repo directory or where you created the symlink.

For example, I would recommend creating a config repo with your .zshrc file and cloning it to all relevant machines. Next, I would create a symlink for your .zshrc from your config repo, ~/dev/config/.zshrc, to its default location, the home directory on all your machines.

cd ~
ln -s ~/dev/config/.zshrc .

Now if that git managed .zshrc file is ever updated on one machine the changes can be pulled on another via the config repo and the .zshrc file symlinked to the home directory is also updated. And visa versa if ~/.zshrc is updated the changes are reflected in the config repo change log and can easily be committed and pushed for other machines to pull.

This setup also works for your oh-my-zsh config. I would recommend following the standard install procedure on each machine thanks to it essentially cloning from source into at own local git directory. However, the .oh-my-zsh/custom directory is what you'll want to be in sync for your custom functions, aliases, templates, plugins, etc.

cd ~/.oh-my-zsh
rm -rf custom
ln -s ~/dev/config/oh-my-zsh/custom .

This solution enables tracking your zsh and oh-my-zsh configs in version control for maintainability and enables interoperability between machines. This can of course be extended to any type of config files/directories.

Note: all of this could of course be automated with a provisioning config tool like puppet, anasable, or chef. Furthermore, the management of the symlinks could be assisted with a solution such as Stow.

rsmets
  • 789
  • 1
  • 13
  • 23
0

You should use a dotfiles manager, there are many different ones.

I would recommend yadm

You can see an example in my dotfiles repo: https://github.com/khongi/dotfiles

Khongor Bayarsaikhan
  • 1,644
  • 1
  • 16
  • 19