From 085fff8534e51c1370afae244683c1f2604727a5 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 3 May 2019 09:45:06 +0200 Subject: [PATCH] Scripts now work with bash --- zsh/bin/copy | 2 +- zsh/bin/swap | 6 ++-- zsh/bin/update | 68 ++++++++++++++++++++++----------------------- zsh/bin/vim-recover | 2 +- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/zsh/bin/copy b/zsh/bin/copy index d32a86b..27593e0 100755 --- a/zsh/bin/copy +++ b/zsh/bin/copy @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash if [ $# -eq 0 ]; then xclip -selection c diff --git a/zsh/bin/swap b/zsh/bin/swap index bb1e94f..ee51a9a 100755 --- a/zsh/bin/swap +++ b/zsh/bin/swap @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash # Swap files if [ $# -ne 2 ]; then @@ -7,12 +7,12 @@ if [ $# -ne 2 ]; then fi if [ -f $1 ] && [ -f $2 ]; then - local tmp=`mktemp` + tmp=`mktemp` mv "$1" "$tmp" mv "$2" "$1" mv "$tmp" "$2" elif [ -d $1 ] && [ -d $2 ]; then - local tmp=`mktemp -d` + tmp=`mktemp -d` mv "$1" "$tmp" mv "$2" "$1" mv "$tmp/$1" "$2" diff --git a/zsh/bin/update b/zsh/bin/update index 77f7b10..69cbd1f 100755 --- a/zsh/bin/update +++ b/zsh/bin/update @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash _check_date_if_format() { local format=`_date_format` @@ -32,23 +32,23 @@ _sentence() { 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` + n_subject0=`shuf -i0-"$((${#subject0[@]}-1))" -n1` + n_subject1=`shuf -i0-"$((${#subject1[@]}-1))" -n1` + n_adjective=`shuf -i0-"$((${#adjective[@]}-1))" -n1` + n_adverb=`shuf -i0-"$((${#adverb[@]}-1))" -n1` + n_dot=`shuf -i0-"$((${#dot[@]}-1))" -n1` if [ $1 = "updated" ]; then color="32" - n_verb=`shuf -i1-"${#verb[@]}" -n1` - s_verb=$verb[$n_verb] + n_verb=`shuf -i0-"$((${#verb[@]}-1))" -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] + n_verb=`shuf -i0-"$((${#no_verb[@]}-1))" -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" + echo -e "\033[$color;1m${subject0[$n_subject0]} ${adjective[$n_adjective]} ${subject1[$n_subject1]} $s_verb ${adverb[$n_adverb]}${dot[$n_dot]}\033[0m" } _check_date() { @@ -67,14 +67,14 @@ _check_date() { update-system() { - echo "\033[32;1m=== Starting system update, please enter your password ===\033[0m" + echo -e "\033[32;1m=== Starting system update, please enter your password ===\033[0m" sudo true if [ $? -ne 0 ]; then echo "Could not get sudo..." return 1 fi - echo "\033[32;1m=== Updating system ===\033[0m" + echo -e "\033[32;1m=== Updating system ===\033[0m" start_system_update=`date +%s` # Debian based systems @@ -111,7 +111,7 @@ update-system() { seconds=$((`date +%s` - $start_system_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== System updated in $formatted ===\033[0m" + echo -e "\033[32;1m=== System updated in $formatted ===\033[0m" } update-rust() { @@ -123,10 +123,10 @@ update-rust() { fi start_rust_update=`date +%s` - echo "\033[32;1m=== Updating rustup ===\033[0m" + echo -e "\033[32;1m=== Updating rustup ===\033[0m" rustup self update - echo "\033[32;1m=== Updating rust ===\033[0m" + echo -e "\033[32;1m=== Updating rust ===\033[0m" rustup update cargo install-update --help > /dev/null 2>&1 @@ -153,29 +153,29 @@ update-rust() { sudo dnf install openssl-devel fi elif echo $sudoresult | grep -q '^sudo:'; then - echo "\033[32;1m=== libssl-dev is needed to update rust packages, please enter your password ===\033[0m" + echo -e "\033[32;1m=== libssl-dev is needed to update rust packages, please enter your password ===\033[0m" sudo true if [ $? -ne 0 ]; then echo "Could not get sudo..." return 1 fi else - echo "\033[33;1m=== You are not a sudoer, cannot install cargo-update... ===\033[0m" + echo -e "\033[33;1m=== You are not a sudoer, cannot install cargo-update... ===\033[0m" return 1 fi fi - echo "\033[32;1m=== Installing rust packages updater ===\033[0m" + echo -e "\033[32;1m=== Installing rust packages updater ===\033[0m" cargo install cargo-update fi - echo "\033[32;1m=== Updating rust packages ===\033[0m" + echo -e "\033[32;1m=== Updating rust packages ===\033[0m" cargo install-update -ag seconds=$((`date +%s` - $start_rust_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Rust updated in $formatted ===\033[0m" + echo -e "\033[32;1m=== Rust updated in $formatted ===\033[0m" } @@ -192,7 +192,7 @@ update-npm() { fi start_npm_update=`date +%s` - echo "\033[32;1m=== Updating node packages ===\033[0m" + echo -e "\033[32;1m=== Updating node packages ===\033[0m" for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3) do @@ -201,7 +201,7 @@ update-npm() { seconds=$((`date +%s` - $start_npm_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Node packages updated in $formatted ===\033[0m" + echo -e "\033[32;1m=== Node packages updated in $formatted ===\033[0m" } update-dotfiles() { @@ -209,14 +209,14 @@ update-dotfiles() { current_dir=$PWD - echo "\033[32;1m=== Updating oh-my-zsh ===\033[0m" + echo -e "\033[32;1m=== Updating oh-my-zsh ===\033[0m" cd ~/.config/oh-my-zsh && git pull - echo "\033[32;1m=== Updating dotfiles ===\033[0m" + echo -e "\033[32;1m=== Updating dotfiles ===\033[0m" cd ~/.config/dotfiles && git pull if [ -d ~/.config/awesome/.git ]; then - echo "\033[32;1m=== Updating awesome config ===\033[0m" + echo -e "\033[32;1m=== Updating awesome config ===\033[0m" cd ~/.config/awesome/ && git pull fi @@ -224,7 +224,7 @@ update-dotfiles() { seconds=$((`date +%s` - $start_dotfiles_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m" + echo -e "\033[32;1m=== Dotfiles updated in $formatted ===\033[0m" } update-neovim() { @@ -234,13 +234,13 @@ update-neovim() { fi start_neovim_update=`date +%s` - echo "\033[32;1m=== Updating neovim packages ===\033[0m" + echo -e "\033[32;1m=== Updating neovim packages ===\033[0m" nvim +PlugUpdate +qall seconds=$((`date +%s` - $start_neovim_update )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Neovim updated in $formatted ===\033[0m" + echo -e "\033[32;1m=== Neovim updated in $formatted ===\033[0m" } _print_help() { @@ -248,7 +248,7 @@ _print_help() { } partial-test() { - case $1 in; + case $1 in "system") return 0;; "rust") return 0;; "npm") return 0;; @@ -261,7 +261,7 @@ partial-test() { } partial-update() { - case $1 in; + case $1 in "system") update-system;; "rust") update-rust;; "npm") update-npm;; @@ -278,7 +278,7 @@ main() { if [ $# -eq 0 ]; then start=`date +%s` - echo "\033[32;1m=== Starting full update ===\033[0m" + echo -e "\033[32;1m=== Starting full update ===\033[0m" # Update the system update-system @@ -304,7 +304,7 @@ main() { seconds=$((`date +%s` - $start )) formatted=`date -ud "@$seconds" +'%H hours %M minutes %S seconds'` - echo "\033[32;1m=== Update finished in $formatted ===\033[0m" + echo -e "\033[32;1m=== Update finished in $formatted ===\033[0m" _check_date_if_format force @@ -313,7 +313,7 @@ main() { for part in $@; do partial-test $part if [ $? -ne 0 ]; then - echo "\033[1;31merror:\033[0m unrocognized update command \"$part\"" + echo -e "\033[1;31merror:\033[0m unrocognized update command \"$part\"" return 1 fi done diff --git a/zsh/bin/vim-recover b/zsh/bin/vim-recover index b57c260..335fc82 100755 --- a/zsh/bin/vim-recover +++ b/zsh/bin/vim-recover @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#!/usr/bin/env bash # Check recovery directory from vim if [ -f $1 ]; then