'Manage dotfiles inhibiting hardcoded paths? [closed]
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 1:[1]
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.
Solution 2:[2]
I'm using symlinks, and not consider it as "dirty hack". Previously i was simple copying all files (and still doing this for the some files (not bash)), and because all files are for $HOME/.something i was used "$HOME" (not '~', because '~' was not expanded in double quotes but $HOME yes.)
Solution 3:[3]
It's really late reply, but still I will recommend you to check DFM (dotfiles manager). DFM addresses the problem you have in a very clean way:
- Here is my dotfiles selection using dfm: vicente's dotfiles
- Github official repository DFM site
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | cumizgumy |
| Solution 3 |
