summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-11-24 17:17:12 +0100
committerAnton Khirnov <anton@khirnov.net>2020-11-24 17:17:12 +0100
commit420b61bf28bb9b8db166f5979a589547102258b8 (patch)
tree8886f3cdca7ee6795dccb0dfeb8d2ca913900378
parentbee37840a646f03e834c92180ad366f382e2e9cc (diff)
Add a bash prompt notification for dirty/outdated dotfiles.
-rwxr-xr-xbash/prompt4
-rwxr-xr-xcron/dotfiles_status21
-rw-r--r--cron_hook4
-rw-r--r--install.conf.yaml3
4 files changed, 31 insertions, 1 deletions
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