Search code examples
macosbashunixdotfiles

Manage dotfiles inhibiting hardcoded paths?


Today I decided to manage and push my dotfiles in the repository. The motivation is to reuse the same dotfiles on multiple mac machines and ubuntu server machines.

I currently have thought of this structure:

├── bash
│   ├── aliases
│   ├── config
│   └── env
├── bash_profile
├── bashrc
├── hgrc
├── src
│   └── link.py
└── vimrc

link.py runs and creates symlinks for bashrc and bash_profile from ~ to where-ever this repository is cloned to.

Problem: 1

my bashrc contents:

source bash/env
source bash/config
source bash/aliases

The problem is because the paths are relative, the files are not found. I don't want to use an absolute path because then I lose the flexibility to clone the repository anywhere I like.

similarly, my bash_profile contents:

source ./bashrc                       # same problem!
source ~/.bashrc                 

since I previously symlinked ~/.bashrc to dotfiles/bashrc I can reach it. But it still seems like a dirty hack to me.

Problem: 2

Where should I keep my paths which are custom to particular machine. Surely I don't want to put them in the repository and mess up every other system as well. Currently my custom paths are in ~/.profile. I am thinking to source it from bash/env with an if to check if it exists then use it otherwise not.

Would love to hear better approaches


Solution

  • Since I did not get much response here, I have resorted to expanding my src/link.py to symlink ~/.bash to dotfiles/bash so that I can reach bash/* using ~/.bash/*

    I have also added a ignore list in my link.py to ignore .hg, bin directories so that they are not symlinked when doing a os.listdir().

    I am still looking for a solution for my second problem, although I read somewhere that I can use separate branches for my dotfiles for each machine which have specific customization needs, and it seems to be the most closest clean solution right now.