My ~/dotfile setup
This method involves using a Bare Git repo. You can find the dotfiles for my daily driver here
Content⌗
Starting a new repo⌗
Create a bare repo and an alias for git to work in that repo.
Hide untracked files in config status
.
Put the alias in your shell config (e.g. bashrc).
This way, you can use the alias when you open a new shell.
git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
An example on how to use it:
config status
config add .vimrc
config commit -m "Add vimrc"
config remote add https://github.com/fpkmatthi/dotfiles-ideapad.git
config push -u origin
Deploying dotfiles on a new system⌗
Configure the alias, let the source repo ignore the folder where it will be cloned and then clone the repo.
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
echo ".cfg" >> .gitignore
git clone --bare <git-repo-url> $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
Checkout the actual content from the repo.
config checkout
If you receive an error like this:
error: The following untracked working tree files would be overwritten by checkout:
.bashrc
.gitignore
Please move or remove them before you can switch branches.
Aborting
Backup the files that cause an error and checkout again.
mkdir -p .config-backup && \
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} .config-backup/{}
config checkout
Hide untracked files in config status
.
config config --local status.showUntrackedFiles no
Final script⌗
#!/usr/bin/env sh
# deploy-dotfiles.sh
git clone --bare https://github.com/fpkmatthi/dotfiles-ideapad.git $HOME/.cfg
function config() {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out config."
else
echo "Backing up pre-existing dot files."
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{}
fi
config checkout
config config status.showUntrackedFiles no
Post deploy steps⌗
- Install the Hack font, located in ~/.config/hack
cp -r ~/.config/hack /usr/share/fonts
fc-cache -f -v
Test the setup on a container⌗
docker run -it -v $PWD:/src alpine /bin/sh /src/deploy-dotfiles.sh
docker run -it -v $PWD:/src alpine /bin/ls
References⌗
Read other posts