add installer and prompt notifier for changed config

This commit is contained in:
Knut Ahlers 2016-07-21 17:05:41 +02:00
parent 5ad81baf8b
commit 53f294f398
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 45 additions and 1 deletions

View file

@ -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}"

7
bin/config-git-status.sh Executable file
View file

@ -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

28
bin/ensure-config.sh Executable file
View file

@ -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