From b384854a4f7d6ed76374d47566c05c674a198bd4 Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Tue, 25 Aug 2020 14:16:28 +0200 Subject: [PATCH] Move long commands from dotbot config into scripts Move long commands from the dotbot config into own scripts to keep the install.conf.yaml more readable. Fix bug that the submodule init step fails when already done once since then the grep statement fails because there is no output. --- meta/archive | 20 ++++++++++++++++++++ meta/install.conf.yaml | 5 ++--- meta/submodules | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 meta/archive create mode 100644 meta/submodules diff --git a/meta/archive b/meta/archive new file mode 100644 index 0000000..fe93169 --- /dev/null +++ b/meta/archive @@ -0,0 +1,20 @@ +#!/bin/sh + +tmpd="$(mktemp -d)" + +for file in .config/*; do + [ ! -e "$HOME/$file" ] || mv "$HOME/$file" "$tmpd" +done + +if rmdir "$tmpd" 2>/dev/null; then + echo "Nothing to archive" +else + name="existing-$(date +"%s").tar.gz" + if tar czvf "$name" "$tmpd"; then + rm -rf "$tmpd" + echo "$name created" + else + echo "Archive could not be created. See $tmpd." + exit 1 + fi +fi diff --git a/meta/install.conf.yaml b/meta/install.conf.yaml index 8dc2ef7..4538baa 100644 --- a/meta/install.conf.yaml +++ b/meta/install.conf.yaml @@ -1,15 +1,14 @@ - shell: - - command: git submodule update --init --recursive --jobs 8 --depth 1 2>&1 | grep "Cloning into" + command: meta/submodules --init description: Pulling all submodules stdout: true stderr: true - - command: /bin/sh -c 'tmpd="$(mktemp -d)"; for file in .config/*; do [ ! -e "$HOME/$file" ] || mv "$HOME/$file" "$tmpd"; done; rmdir "$tmpd" 2>/dev/null && echo "Nothing to archive" || { name="existing-$(date +"%s").tar.gz"; tar czvf "$name" "$tmpd" && rm -rf "$tmpd" && echo "$name created"; }' + command: meta/archive description: Archiving all files in ~/.config before overwriting them stdout: true stderr: true - quiet: true - command: .config/zsh/plugins/fzf/install --bin description: Pulling fzf binary diff --git a/meta/submodules b/meta/submodules new file mode 100644 index 0000000..b658eed --- /dev/null +++ b/meta/submodules @@ -0,0 +1,18 @@ +#!/bin/bash + +[ $# -eq 1 ] || { echo "Specify what to do" >&2; exit 1; } + +case "$1" in + "--init") INIT=1;; + "--update") INIT=0;; + *) echo "Unknown option"; exit 1;; +esac + +if (( $INIT )); then + out="$(git submodule update --init --recursive --jobs 8 --depth 1 2>&1)" + if ! (( $? )) && [ -n "$out" ] ; then + echo "$out" | grep "Cloning into" + fi +else + git submodule update --remote +fi