From 68b0d8f2c467361b7a2229dcd12930ade59db82d Mon Sep 17 00:00:00 2001 From: AtomicCoding Date: Mon, 16 Apr 2018 17:39:48 -0700 Subject: [PATCH 1/5] Add module updater --- modules/utility/README.md | 8 ++++ modules/utility/functions/module_update | 62 +++++++++++++++++++++++++ templates/zimrc | 8 ++++ 3 files changed, 78 insertions(+) create mode 100644 modules/utility/functions/module_update diff --git a/modules/utility/README.md b/modules/utility/README.md index e5dda67..7aec67a 100644 --- a/modules/utility/README.md +++ b/modules/utility/README.md @@ -46,3 +46,11 @@ Aliases `get` to ( `aria2c` || `axel` || `wget` || `curl` ). | alias | description | | ----- | ----------- | | `mkcd` | `mkdir -p` and `cd` | + +Commands +-------- + +| command | description | +| ----- | ----------- | +| `module_update` | `Updates git-installed modules and themes specified in the zimrc` | + diff --git a/modules/utility/functions/module_update b/modules/utility/functions/module_update new file mode 100644 index 0000000..c0bb512 --- /dev/null +++ b/modules/utility/functions/module_update @@ -0,0 +1,62 @@ +local currentdir=$(pwd) +local commandgood="0" +local updated=0 +local failed=0 +local module +local mlocation +for module in $umodules; do + if [ -d ${ZIM_HOME}/modules/${module} ]; then + mlocation=${ZIM_HOME}/modules/${module} + elif [ -d ${ZIM_HOME}/modules/prompt/external-themes/${module} ]; then + mlocation=${ZIM_HOME}/modules/prompt/external-themes/${module} + else + echo "$fg[red]Cant find $module module...$reset_color" + break + fi + echo -ne "$fg[blue]Updating $module... $reset_color"\\r + output=$(cd $mlocation && git remote update -p && git merge --ff-only @\{u\}) + if [ $? -ne 0 ]; then + echo -ne "$fg[red]Failed to update $module...\n $output $reset_color"\\r + failed=$((failed+1)) + fi + if echo "$output" | grep -i "up to date" > /dev/null; then + echo -ne "$fg[blue]$module at latest version. $reset_color"\\r + else + echo -ne "$fg[green]Updated $module! $reset_color"\\r + updated=$((updated+1)) + fi + printf '\n' +done +for pmodule in $pmodules; do + echo -ne "$fg[blue]Updating $pmodule... $reset_color"\\r + output=$(cd ${ZIM_HOME}/modules/prompt/external-themes/$pmodule && git remote update -p && git merge --ff-only @\{u\}) + if [ $? -ne 0 ]; then + echo -ne "$fg[red]Failed to update $pmodule...\n $output $reset_color"\\r + failed=$((failed+1)) + fi + if echo "$output" | grep -i "up to date" > /dev/null; then + echo -ne "$fg[blue]$pmodule at latest version. $reset_color"\\r + else + echo -ne "$fg[green]Updated $pmodule! $reset_color"\\r + updated=$((updated+1)) + fi + printf '\n' +done +if [ $updated -gt 0 ]; then + if [ $failed -eq 0 ]; then + echo "$fg[green]\033[1mSucessfully updated $updated modules!$reset_color" + fi +else + if [ $failed -eq 0 ]; then + echo "$fg[blue]\033[1mNo module updates avaliable.$reset_color" + fi +fi +if [ $failed -gt 0 ]; then + if [ $updated -gt 0 ]; then + echo "$fg[blue]\033[1mSucessfully updated $updated modules and failed to update $failed modules.$reset_color" + else + echo "$fg[red]\033[1mFailed to update $failed modules, no module updates available.$rest_color" + fi + +fi +cd $currentdir \ No newline at end of file diff --git a/templates/zimrc b/templates/zimrc index 203a7a6..db36679 100644 --- a/templates/zimrc +++ b/templates/zimrc @@ -53,6 +53,14 @@ zprompt_theme='steeef' # The example below uses the following format: 'username@host:/current/directory' ztermtitle='%n@%m:%~' +# +# Updater +# + +# Set modules or themes to update (they must be a valid git repo) +#umodules=() + + # # Input # From 147478cde65db4a7e145d98bd0f81fe84454e6ba Mon Sep 17 00:00:00 2001 From: Atomic Coding Date: Mon, 16 Apr 2018 17:42:34 -0700 Subject: [PATCH 2/5] Remove useless code --- modules/utility/functions/module_update | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/utility/functions/module_update b/modules/utility/functions/module_update index c0bb512..c631c11 100644 --- a/modules/utility/functions/module_update +++ b/modules/utility/functions/module_update @@ -1,5 +1,4 @@ local currentdir=$(pwd) -local commandgood="0" local updated=0 local failed=0 local module @@ -59,4 +58,4 @@ if [ $failed -gt 0 ]; then fi fi -cd $currentdir \ No newline at end of file +cd $currentdir From 703a76f63252038684620dc07a7a695d73d7795f Mon Sep 17 00:00:00 2001 From: AtomicCoding Date: Mon, 16 Apr 2018 17:52:31 -0700 Subject: [PATCH 3/5] Fixed and Changes --- modules/utility/functions/module_update | 45 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/modules/utility/functions/module_update b/modules/utility/functions/module_update index c631c11..ba937be 100644 --- a/modules/utility/functions/module_update +++ b/modules/utility/functions/module_update @@ -3,58 +3,77 @@ local updated=0 local failed=0 local module local mlocation +local ncolors red green yelllow blue bold normal +if which tput >/dev/null 2>&1; then + ncolors=$(tput colors) + fi +if [ -t 1 ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then + red=$(tput setaf 1) + green=$(tput setaf 2) + yellow=$(tput setaf 3) + blue=$(tput setaf 4) + bold=$(tput bold) + normal=$(tput sgr0) +else + red="" + green="" + yellow="" + blue="" + bold="" + normal="" +fi for module in $umodules; do if [ -d ${ZIM_HOME}/modules/${module} ]; then mlocation=${ZIM_HOME}/modules/${module} elif [ -d ${ZIM_HOME}/modules/prompt/external-themes/${module} ]; then mlocation=${ZIM_HOME}/modules/prompt/external-themes/${module} else - echo "$fg[red]Cant find $module module...$reset_color" + echo "${red}Cant find $module module...$normal" break fi - echo -ne "$fg[blue]Updating $module... $reset_color"\\r + echo -ne "${blue}Updating $module... $normal"\\r output=$(cd $mlocation && git remote update -p && git merge --ff-only @\{u\}) if [ $? -ne 0 ]; then - echo -ne "$fg[red]Failed to update $module...\n $output $reset_color"\\r + echo -ne "${red}Failed to update $module...\n $output $normal"\\r failed=$((failed+1)) fi if echo "$output" | grep -i "up to date" > /dev/null; then - echo -ne "$fg[blue]$module at latest version. $reset_color"\\r + echo -ne "${blue}$module at latest version. $normal"\\r else - echo -ne "$fg[green]Updated $module! $reset_color"\\r + echo -ne "${green}Updated $module! $normal"\\r updated=$((updated+1)) fi printf '\n' done for pmodule in $pmodules; do - echo -ne "$fg[blue]Updating $pmodule... $reset_color"\\r + echo -ne "${blue}Updating $pmodule... $normal"\\r output=$(cd ${ZIM_HOME}/modules/prompt/external-themes/$pmodule && git remote update -p && git merge --ff-only @\{u\}) if [ $? -ne 0 ]; then - echo -ne "$fg[red]Failed to update $pmodule...\n $output $reset_color"\\r + echo -ne "${red}Failed to update $pmodule...\n $output $normal"\\r failed=$((failed+1)) fi if echo "$output" | grep -i "up to date" > /dev/null; then - echo -ne "$fg[blue]$pmodule at latest version. $reset_color"\\r + echo -ne "${blue}$pmodule at latest version. $normal"\\r else - echo -ne "$fg[green]Updated $pmodule! $reset_color"\\r + echo -ne "${green}Updated $pmodule! $normal"\\r updated=$((updated+1)) fi printf '\n' done if [ $updated -gt 0 ]; then if [ $failed -eq 0 ]; then - echo "$fg[green]\033[1mSucessfully updated $updated modules!$reset_color" + echo "${green}${bold}Sucessfully updated $updated modules!$normal" fi else if [ $failed -eq 0 ]; then - echo "$fg[blue]\033[1mNo module updates avaliable.$reset_color" + echo "${blue}${bold}No module updates avaliable.$normal" fi fi if [ $failed -gt 0 ]; then if [ $updated -gt 0 ]; then - echo "$fg[blue]\033[1mSucessfully updated $updated modules and failed to update $failed modules.$reset_color" + echo "${blue}${bold}Sucessfully updated $updated modules and failed to update $failed modules.$normal" else - echo "$fg[red]\033[1mFailed to update $failed modules, no module updates available.$rest_color" + echo "${red}${bold}Failed to update $failed modules, no module updates available.$normal" fi fi From a7844c828456a54a087798d77b1371eaafeac10d Mon Sep 17 00:00:00 2001 From: Atomic Coding Date: Mon, 16 Apr 2018 18:07:03 -0700 Subject: [PATCH 4/5] Styling change --- templates/zimrc | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/zimrc b/templates/zimrc index db36679..107f020 100644 --- a/templates/zimrc +++ b/templates/zimrc @@ -53,6 +53,7 @@ zprompt_theme='steeef' # The example below uses the following format: 'username@host:/current/directory' ztermtitle='%n@%m:%~' + # # Updater # From 7aecb170b6f8b7e7272c27ccc660bbf90300a178 Mon Sep 17 00:00:00 2001 From: AtomicCoding Date: Mon, 16 Apr 2018 19:45:52 -0700 Subject: [PATCH 5/5] Fix with failed updates --- modules/utility/functions/module_update | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/utility/functions/module_update b/modules/utility/functions/module_update index ba937be..daac3d1 100644 --- a/modules/utility/functions/module_update +++ b/modules/utility/functions/module_update @@ -3,17 +3,18 @@ local updated=0 local failed=0 local module local mlocation +local nfailed local ncolors red green yelllow blue bold normal if which tput >/dev/null 2>&1; then ncolors=$(tput colors) fi if [ -t 1 ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then - red=$(tput setaf 1) - green=$(tput setaf 2) - yellow=$(tput setaf 3) - blue=$(tput setaf 4) - bold=$(tput bold) - normal=$(tput sgr0) + red="$(tput setaf 1)" + green="$(tput setaf 2)" + yellow="$(tput setaf 3)" + blue="$(tput setaf 4)" + bold="$(tput bold)" + normal="$(tput sgr0)" else red="" green="" @@ -23,6 +24,7 @@ else normal="" fi for module in $umodules; do + nfailed=0 if [ -d ${ZIM_HOME}/modules/${module} ]; then mlocation=${ZIM_HOME}/modules/${module} elif [ -d ${ZIM_HOME}/modules/prompt/external-themes/${module} ]; then @@ -36,13 +38,16 @@ for module in $umodules; do if [ $? -ne 0 ]; then echo -ne "${red}Failed to update $module...\n $output $normal"\\r failed=$((failed+1)) + nfailed=1 fi + if ! [ ${nfailed} = "1" ]; then if echo "$output" | grep -i "up to date" > /dev/null; then echo -ne "${blue}$module at latest version. $normal"\\r else echo -ne "${green}Updated $module! $normal"\\r updated=$((updated+1)) fi + fi printf '\n' done for pmodule in $pmodules; do