From bca227ff27bb77a1dd8e27362b2ead584cdad9d9 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Tue, 12 Jul 2022 01:38:47 +0200 Subject: [PATCH] Add installation script for the ~/.dotfiles bare repo --- .config/shell/init_dotfiles.sh | 57 ++++++++++++++++++++++++++++++++++ README.md | 22 +++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 .config/shell/init_dotfiles.sh diff --git a/.config/shell/init_dotfiles.sh b/.config/shell/init_dotfiles.sh new file mode 100755 index 0000000..9cb7c40 --- /dev/null +++ b/.config/shell/init_dotfiles.sh @@ -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 diff --git a/README.md b/README.md index 7c57cc5..3625b50 100644 --- a/README.md +++ b/README.md @@ -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!