From 3d841c8360ef2262325a0cf59c89ca0b740758bf Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 15 Jun 2020 04:38:18 -0500 Subject: [PATCH] add system update warning --- dot_local/scripts/zsh/aliases.zsh | 22 ++++++++++++++++++- .../scripts/zsh/executable_check-update.zsh | 21 ++++++++++++++++++ dot_zshrc | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 dot_local/scripts/zsh/executable_check-update.zsh diff --git a/dot_local/scripts/zsh/aliases.zsh b/dot_local/scripts/zsh/aliases.zsh index cadc876..2d6a867 100644 --- a/dot_local/scripts/zsh/aliases.zsh +++ b/dot_local/scripts/zsh/aliases.zsh @@ -3,5 +3,25 @@ alias rm="garbage put" alias cm="chezmoi" alias kill-gpg-agent="gpgconf --kill gpg-agent" -ced() { chezmoi edit $1 && chezmoi -v apply } +function ced() { + # if the file doesn't exist, prompt to make a new one + if [ ! -f "$1" ]; then + read "?$1 doesn't exist.. create file? [yN] " yn + case $yn in + [Yy]* ) + echo "creating new file" + install -D /dev/null $1 + echo "\n" > $1 + chezmoi add $1;; + * ) + echo "nah" + return;; + esac + fi + + chezmoi edit $1 + echo "applying changes..." + chezmoi apply +} + cpush() { chezmoi git add . -- -A && chezmoi git commit -- -m "update" && chezmoi git push } diff --git a/dot_local/scripts/zsh/executable_check-update.zsh b/dot_local/scripts/zsh/executable_check-update.zsh new file mode 100644 index 0000000..ae3cc9d --- /dev/null +++ b/dot_local/scripts/zsh/executable_check-update.zsh @@ -0,0 +1,21 @@ +function checkUpdate() { + lastUpdateFile=$HOME/.config/last-system-update + + if [ ! -f "$lastUpdateFile" ]; then + echo "this system hasn't ever been updated using system-upgrade.sh" + echo "run system-upgrade.sh now" + return + fi + + lastUpdate=$(cat $lastUpdateFile) + now=$(date "+%s") + + if [ $(( $now - $lastUpdate > 604800 )) ]; then + echo "this system hasn't been updated for over a week" + echo "run system-upgrade.sh asap" + return + fi +} + +checkUpdate + diff --git a/dot_zshrc b/dot_zshrc index 119a86b..e2518e8 100644 --- a/dot_zshrc +++ b/dot_zshrc @@ -1,4 +1,5 @@ source $HOME/.local/scripts/zsh/zsh-prelude.zsh +source $HOME/.local/scripts/zsh/check-update.zsh export LANG=en_US.UTF-8 export ZSH="/home/michael/.oh-my-zsh"