Search code examples
mercurialhgrc

Cross-platform hgrc solution?


I'm looking for a solution to have one .hgrc for mercurial to work in all my working environments(win/lin/mac), just like one vimrc to rule all.

It comes to a problem when I have to specify the path for some extensions, for example, hg-git:

on windows:

[extensions]
hggit = E:\hg-git\hggit

on linux/mac:

[extensions]
hggit = ~/hg-git/hggit

For vimrc, we have solution to distinguish different platform, like

if has('win32')
  ...
endif

Knowing that mercurial's hgrc is barely a normal ini file, I wonder if there is similar solution for hgrc file.

Or maybe some other solution?

Update

Thanks for mentioning using "custom environment variable instead of hard coding", that works for extensions' path.

However, to make extensions work is just one goal. I believe there are other configurations' behavior that depends on platform, like in http://www.ogre3d.org/docs/OGREDeveloperGuide/index.html, specific options are needed for Windows and Mac. How to solve this kind of problem?


Solution

  • How about using the .hgrc include mechanism and three separate files:

    ~/.hgrc
    ~/.hgrc-windows
    ~/.hgrc-linux
    

    where the main ~/.hgrc has:

    %include .hgrc-$OS
    

    and then set $OS in your windows profile and your linux profile's. Alternately you could probably find an env variable that already exists on both systems ($USERNAME is usally already set in both windows and unix and may differ for you).