From b71d8f6e6d906108e41ad4900d060d49c5bcbe92 Mon Sep 17 00:00:00 2001 From: Thibault Blanc Beyne Date: Fri, 1 Feb 2019 11:54:10 +0100 Subject: [PATCH] Add message when the system needs update --- .gitignore | 2 ++ zsh/update.zsh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/.gitignore b/.gitignore index c3617f6..886e38d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ zsh/extraconfig.zsh + +.data diff --git a/zsh/update.zsh b/zsh/update.zsh index 93934a9..e67ed45 100644 --- a/zsh/update.zsh +++ b/zsh/update.zsh @@ -1,3 +1,49 @@ +_check_date_file() { + mkdir -p ~/.config/dotfiles/.data + touch ~/.config/dotfiles/.data/update_date +} + +_sentence() { + subject0=("Your" "The" "This") + subject1=("system" "machine" "pc" "computer") + adjective=("awesome" "incredible" "amazing" "brave" "hard working" "loyal" "nice" "polite" "powerful" "pro-active" "reliable" "fabulous" "fantastic" "incredible" "outstanding" "remarkable" "spectacular" "splendid" "super" "happy" "cheerful") + verb=("is" "seems" "looks" "appears to be") + no_verb=("is not" "doesn't seem" "doesn't look" "appears not to be") + adverb=("up-to-date" "ready" "updated") + dot=("." "!" "...") + + n_subject0=`shuf -i1-"${#subject0[@]}" -n1` + n_subject1=`shuf -i1-"${#subject1[@]}" -n1` + n_adjective=`shuf -i1-"${#adjective[@]}" -n1` + n_adverb=`shuf -i1-"${#adverb[@]}" -n1` + n_dot=`shuf -i1-"${#dot[@]}" -n1` + + if [ $1 = "updated" ]; then + color="32" + n_verb=`shuf -i1-"${#verb[@]}" -n1` + s_verb=$verb[$n_verb] + elif [ $1 = "not_updated" ]; then + color="31" + n_verb=`shuf -i1-"${#no_verb[@]}" -n1` + s_verb=$no_verb[$n_verb] + fi + + echo "\033[$color;1m$subject0[$n_subject0] $adjective[$n_adjective] $subject1[$n_subject1] $s_verb $adverb[$n_adverb]$dot[$n_dot]\033[0m" +} + +_check_date() { + _check_date_file + + old_date=`cat ~/.config/dotfiles/.data/update_date` + new_date=`date +%d/%m/%y` + + if [ "$new_date" != "$old_date" ]; then + _sentence not_updated + else + _sentence updated + fi +} + update-system() { # Ask for sudo right now @@ -161,4 +207,6 @@ update() { formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` echo "\033[32;1m=== Update finished in $formatted ===\033[0m" + _check_date_file + date +%d/%m/%y > ~/.config/dotfiles/.data/update_date }