Question

I've started using version control and syncing on my various dotfiles using the extremely handy GNU Stow thanks to a recommendation on here.

However, I am not sure how to properly stow my .bashrc for syncing across computers, as it contains machine-specific PATH lines that I would obviously not want to sync. Is there a proper way to handle these types of machine-specific lines while syncing dotfiles?

Was it helpful?

Solution

Machine-specific settings should be isolated to a separate file which can be sourced from .bashrc. So your .bashrc might contain a line like

[[ -f .bashrc.local ]] && . .bashrc.local

Then anything that is specific to a local machine, rather than intended to be shared across machines, would be put in .bashrc.local instead. Only .bashrc gets synced.

This does present difficulties if you don't want to isolate all machine-specific settings to one point in your shared .bashrc file. The alternative is to fill your shared .bashrc file with conditional code like

case $HOST in
 machineA )  do-this ;;
 machineB )  do-that ;;
 * ) default-behavior ;;
esac

which takes the current value of $HOST into consideration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top