From 53f294f398ae35b8912d2c71450c141665023569 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 21 Jul 2016 17:05:41 +0200 Subject: [PATCH] add installer and prompt notifier for changed config --- .zsh/oh-my-custom/luzifer.zsh-theme | 11 ++++++++++- bin/config-git-status.sh | 7 +++++++ bin/ensure-config.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 bin/config-git-status.sh create mode 100755 bin/ensure-config.sh diff --git a/.zsh/oh-my-custom/luzifer.zsh-theme b/.zsh/oh-my-custom/luzifer.zsh-theme index 353a4b8..b011595 100644 --- a/.zsh/oh-my-custom/luzifer.zsh-theme +++ b/.zsh/oh-my-custom/luzifer.zsh-theme @@ -29,6 +29,14 @@ function awsenv_prompt { [ -z "${pr}" ] || echo "${bracket_open} ${pr} ${bracket_close}" } +function config-git_prompt { + if [ -f ~/bin/config-git-status.sh ]; then + if ! ( ~/bin/config-git-status.sh ); then + echo "${bracket_open} %{$fg[red]%} ${bracket_close}" + fi + fi +} + function build_git_prompt { $( test "${NO_RIGHT}" = "true" ) && return git branch >/dev/null 2>/dev/null || return @@ -78,9 +86,10 @@ local prompt_part_user="${bracket_open} %{$FG[040]%}%n%{$reset_color%}%{$FG[239] local prompt_part_path="%{$terminfo[bold]$FG[226]%}${current_dir}%{$reset_color%}" local prompt_part_exit="%(?..${bracket_open} %{$fg[red]%}%?%{${reset_color}%} ${bracket_close})" local prompt_part_char='$(prompt_char)' +local prompt_part_configgit='$(config-git_prompt)' PROMPT=" -╭─ ${prompt_part_time}${prompt_part_user}$(awsenv_prompt)${prompt_part_exit} ${prompt_part_path} +╭─ ${prompt_part_time}${prompt_part_user}${prompt_part_configgit}$(awsenv_prompt)${prompt_part_exit} ${prompt_part_path} ╰─${prompt_part_char} " RPROMPT="${git_info}" diff --git a/bin/config-git-status.sh b/bin/config-git-status.sh new file mode 100755 index 0000000..0e00e34 --- /dev/null +++ b/bin/config-git-status.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for i in $(ls -1 ${HOME}/.cfg); do + [ $(git --git-dir=$HOME/.cfg/$i/ --work-tree=$HOME status --porcelain | wc -l) -eq 0 ] || exit 1 +done + +exit 0 diff --git a/bin/ensure-config.sh b/bin/ensure-config.sh new file mode 100755 index 0000000..77c3019 --- /dev/null +++ b/bin/ensure-config.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +PUB_CONFIG="git@github.com:Luzifer/cfg.git" +SEC_CONFIG="git@gitlab.com:luzifer/cfg.git" + +if ! [ -d ${HOME}/.cfg/public ]; then + git clone --bare ${PUB_CONFIG} ${HOME}/.cfg/public +fi + +if ! [ -d ${HOME}/.cfg/secret ]; then + git clone --bare ${SEC_CONFIG} ${HOME}/.cfg/secret +fi + +function config { + git --git-dir=${HOME}/.cfg/${REPO}/ --work-tree=${HOME} $@ +} + +for REPO in public secret; do + 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 +done