Skip to content

Instantly share code, notes, and snippets.

@lijunzh
Last active March 18, 2020 14:49
Show Gist options
  • Save lijunzh/418cbb20940f45564287411fd4d67afd to your computer and use it in GitHub Desktop.
Save lijunzh/418cbb20940f45564287411fd4d67afd to your computer and use it in GitHub Desktop.
Code snippets for install dotfile managed by a git bare repo following https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/
# Suorce: https://news.ycombinator.com/item?id=11071754
repo="https://github.com/lijunzh/dotfiles.git"
# Uncomment if initiate a new dotfiles bare repo
# git init --bare $HOME/.cfg
# Uncomment if install existing dotfiles repo
git clone --bare ${repo} ~/.cfg
# Set temporary config commend, alias should be added in .bashrc
config="/usr/bin/git --git-dir=${HOME}/.cfg/ --work-tree=${HOME}"
${config} config status.showUntrackedFiles no
# Install to $HOME, backup esisting files
mkdir -p .config-backup/.vim/backups
mkdir -p .config-backup/.vim/swaps
mkdir -p .config-backup/.vim/undo
${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/{}
${config} checkout
echo "Checked out config.";
fi;
# config local git repo
$(config) config remote add origin ${repo}
$(config) config remote set-url --fetch origin ${repo}
# install vim-plug if vim is installed
if command -v vim > /dev/null 2>&1; then
# install vim-plug if not been install before
if [ ! -s ~/.vim/autoload/plug.vim ]; then
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
fi
# install vim-plug if neovim is installed
if command -v nvim > /dev/null 2>&1; then
# install vim-plug if not been install before
if [ ! -s ~/.local/share/nvim/site/autoload/plug.vim ]; then
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment