Well, I was going to write about a nifty bit of bash to help with ssh-agent in tmux, but someone beat me to it, so I’ll just write up his idea instead.
Every once in a while, it’s nice to have a bit of bash initialization that only runs on one system. You could just throw that at the end of the .bashrc for that system, but that’s not very persistent. It would be better to have, in the spirit of dotjs, a directory where you drop files with the same name as the host and they get run.
So, here’s a bit of bash initialization that does that and a bit more.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
One additional bit is that it uses successively longer segments of the hostname, so for the hostname
foo.bar.domain.com, the following names are checked, in order:
foo.bar.domain.com. Doing this means that domain-specific initialization is easy and that more specific filenames can override their general counterparts.
The other extra is that if the name exists as a directory, all the files in that directory are sourced. So the full list of checked locations for the above hostname would be:
It works pretty well, but I’m sure it could be better written. I’m not very proficient with bash, so if you have any suggestions for improving it, let me know.