Add installation script for the ~/.dotfiles bare repo

This commit is contained in:
Alexander Hess 2022-07-12 01:38:47 +02:00
parent 9c4ea2ecfe
commit bca227ff27
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
2 changed files with 79 additions and 0 deletions

57
.config/shell/init_dotfiles.sh Executable file
View file

@ -0,0 +1,57 @@
# This file initializes the `~/.dotfiles` bare repo
# Source it from either zsh or bash
# Check if a command can be found on the $PATH.
command_exists() {
command -v "$1" 1>/dev/null 2>&1
}
cd $HOME
# This is only here for documentation purposes
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
# Remove a previous version of a `~/.dotfiles` bare repository
rm -rf "$HOME/.dotfiles" >/dev/null
git clone --bare git@git.webartifex.biz:alexander/dotfiles.git "$HOME/.dotfiles"
# Backup old dotfiles
rm -rf "$HOME/.dotfiles.bak" >/dev/null
mkdir -p $HOME/.dotfiles.bak/.config/{git,shell} && \
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | \
xargs -I{} mv {} "$HOME/.dotfiles.bak"/{}
# Put new dotfiles in $HOME
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout --force
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config --local status.showUntrackedFiles no
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME status
# Set up `zsh` only if it is available
# Note: on many servers I use these dotfiles, `zsh` is not installed
if command_exists zsh; then
# Install oh-my-zsh
export ZSH="$HOME/.oh-my-zsh"
rm -rf $ZSH >/dev/null
git clone https://github.com/ohmyzsh/ohmyzsh.git $ZSH
# Install zplug
export ZPLUG_HOME="$HOME/.zplug"
rm -rf $ZPLUG_HOME >/dev/null
git clone https://github.com/zplug/zplug $ZPLUG_HOME
# Set up all the zplug plugins (must be run interacticely
# so that `~/.zshrc` & friends are sourced again)
zsh -i -c "zplug install"
fi
echo
echo "Probably it's a good idea to restart the shell"
echo "Make sure to start bash or zsh as a login shell the next time"
echo

View file

@ -1,3 +1,25 @@
# Dotfiles
This repository contains useful (config) files that I use on my machines.
## Initialization
On a freshly set up machine, run:
```bash
curl https://gitlab.webartifex.biz/alexander/dotfiles/-/raw/main/.config/shell/init_dotfiles.sh \
> /tmp/init_dotfiles.sh \
&& source /tmp/init_dotfiles.sh \
&& rm /tmp/init_dotfiles.sh
```
This gives you a local copy of the latest version of this repository
(located in `~/.dotfiles`)
and initializes all the dotfiles provided here on your system.
Furthermore, `zsh` is set up with [`oh-my-zsh`](https://ohmyz.sh/) and `zplug`.
**Note**: Log out and in again so that `bash` and `zsh` run as *login* shells.
Otherwise, `~/.profile` is probably *not* sourced.
Don't worry: Your current dotfiles are backed up in the `~/.dotfiles.bak` folder!