I do not know how to make my requirement short in the title, sorry if that does not make sense. I will explain here:
Many people put their dotfiles on bitbucket or github to facilitate subsequent installation or configuration, synchronization on different computers. I did the same, but I want to do something special, I'm not sure how to help mecurial / git.
What I have:
I have 3 machines, for example Home, Office and Client, all Linux OS (there may be different distributions). To make the example simple, let's say I just want to put a single .zshrc file in a repo. The problem is that the three OSs have different system variables (or other settings). eg
- Office has JBOSS installed, then in
.zshrc I need to export JBOSS_HOME var. - The client installed Oracle and then exported a different set of vars.
- Office should export HTTP_PROXY, but HOME isn’t, it also needs a client, but a different proxy value, etc.
Now, what I did, I extract these specific machine parameters (mainly export, alias expression) to another file, say myVar.sh . and enter it at the end of .zshrc .
So, 3 machines have a common part (the same .zshrc ) and different parts ( myVar.sh ).
What I want:
on any machine, if I find some good settings, I modify the .zshrc file (general part) and click. Changes should be easily synchronized with other machines (e.g. pull)
if I changed myVar.sh (the other part) in HOME and clicked, it should not affect Office myVar.sh if I click on Office.
What am I doing:
now I have one repo on a bitbucket and three branches (H, O, C). On a home PC, I just play with the branch "Home". The same for Office, Client.
The problem is that if I changed the common part on one PC, this change is in its own branch, a little difficult to synchronize with the other two. Because I will never merge these branches.
I also think of mk different directories for different computers. eg.
/.zshrc |--/HOME/myVar.sh |--/Office/myVar.sh |--/Client/myVar.sh
and write a shell script, for example. check $ HOST to decide to write myVar.sh to which directory. but I doubt if this is the best way to achieve my goal. And when I look at my point of view, I see all the settings of 3 pcs. I have to be careful and enter the correct one to read the file.
In the real world, the common part contains much more .zhsrc (tmux, vimrc, xdefault ..), as well as the other part.
I don’t know if we can somehow make a partial branch or do a partial merge in the repository ...
I use hg a lot more than git, if hg can solve it, I would prefer hg, if not, git is also valid. I have little git experience except clone, push, pull, up, merge, ci.
now how do i do ?
and thanks for reading this ...
EDIT more about another part
I would like to thank all the guys for the answers. As I said above, different parts of my real machines are not as simple as myVar.sh . For example, I take my laptop company (Office) for different clients (about 6 clients, not all clients provide us with a PC, this is good because I could work with Linux everywhere) and configured printers for each of the cups. I would put these configurations in Repo too. Because if one day I need to upgrade my system or a hard disk failure, I can configure these printers very simply. Other things that belong to another part, but I can’t just “source xxx”, for example
- Xorg.conf for tracking
- .hgrc (since in the company we have our own repo, uid, pwd, proxy ..)
some pre-configured systemd modules, mostly .conf files. But a specific machine, for example. radeon.conf is only for my home laptop. And the client PC is not installed on systemd at all.
That is why I thought of different directories for PC.
As I said right now, I have three branches and have a myConf directory, in this directory I have getConf.sh to copy dotfiles, different confs, etc. in myConf . In fact, getConf.sh also belongs to another part, because the script is not the same for all PCs.
Therefore, I think that if-else/switch then source may not work in this case.
Yesterday I just took .zshrc and tried to make the example simple. If this fools you guys, sorry about that.