From 420b61bf28bb9b8db166f5979a589547102258b8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 Nov 2020 17:17:12 +0100 Subject: Add a bash prompt notification for dirty/outdated dotfiles. --- bash/prompt | 4 +++- cron/dotfiles_status | 21 +++++++++++++++++++++ cron_hook | 4 ++++ install.conf.yaml | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 cron/dotfiles_status create mode 100644 cron_hook diff --git a/bash/prompt b/bash/prompt index b4a1b87..09a75c7 100755 --- a/bash/prompt +++ b/bash/prompt @@ -83,8 +83,10 @@ __prompt_func() { local prompt_usertype_sign="\\$" local prompt_git_branch="$white\$(__git_ps1)$normal" + local dotfiles_dirty="$red\$([ -f ~/.local/var/dotfiles/dirty ] && echo -n \\\!\ )$normal" + # # # # # # # # #FINAL PROMPT # # # # # # # # - echo -n "$prompt_opening_brace $prompt_username@$prompt_hostname_short $prompt_pwd_long$prompt_git_branch$prompt_closing_brace$prompt_usertype_sign " + echo -n "$prompt_opening_brace $dotfiles_dirty$prompt_username@$prompt_hostname_short $prompt_pwd_long$prompt_git_branch$prompt_closing_brace$prompt_usertype_sign " } diff --git a/cron/dotfiles_status b/cron/dotfiles_status new file mode 100755 index 0000000..3fccb0a --- /dev/null +++ b/cron/dotfiles_status @@ -0,0 +1,21 @@ +#!/bin/bash + +# check that the dotfiles repository is up-to-date and clean +# otherwise create the dirty stamp file + +dotfiles_dir=~/.config/dotfiles +dirty_stamp=~/.local/var/dotfiles/dirty + +[ -d "${dotfiles_dir}" ] || (echo "no dotfiles dir" && exit 1) + +git -C "${dotfiles_dir}" fetch -q --all || (echo "error updating remote" && exit 1) +count=$(git -C "${dotfiles_dir}" rev-list --left-right --count '@{upstream}'...HEAD 2>/dev/null | grep -v '^0\s0$') + +git -C "${dotfiles_dir}" diff --exit-code >/dev/null +repo_dirty=$? + +if [[ -n "${count}" || $repo_dirty -ne 0 ]]; then + touch "${dirty_stamp}" +else + rm "${dirty_stamp}" +fi diff --git a/cron_hook b/cron_hook new file mode 100644 index 0000000..9dd937a --- /dev/null +++ b/cron_hook @@ -0,0 +1,4 @@ +# this cronjob should be installed manually in the user's crontab + +# dotfiles daily hook +@daily [ -d ~/.local/var/cron/daily ] && run-parts ~/.local/var/cron/daily diff --git a/install.conf.yaml b/install.conf.yaml index 2f953cd..cb2cec3 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -3,6 +3,8 @@ - ~/.cache/vim/swap - ~/.config/bash - ~/.local/var/bash + - ~/.local/var/cron/daily + - ~/.local/var/dotfiles - ~/.local/var/vim/undo - ~/.vim/colors - ~/.vim/ftplugin/rst @@ -14,6 +16,7 @@ ~/.bashrc: bash/bashrc ~/.gdbinit: dotfiles/gdbinit ~/.gitconfig: dotfiles/gitconfig + ~/.local/var/cron/daily/dotfiles_status: cron/dotfiles_status ~/.profile: dotfiles/profile ~/.tmux.conf: dotfiles/tmux.conf # TODO: clean up and install linediff script -- cgit v1.2.3