From b744cd6624224d61604aa249780b059c42169cea Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Mon, 20 Dec 2021 16:00:30 +0100 Subject: [PATCH] Option -s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -option --nodistract (ou -n) pour exécuter les scripts sans interaction. -option -s 'script' pour exécuter 1 seul script (i.e -s homebrew, -s node, -s pip...) --- kymsu2.sh | 81 +++++++++++++++++++++++++++++++++++++------ plugins.d/antibody.sh | 2 +- plugins.d/gem.sh | 2 +- plugins.d/homebrew.sh | 3 +- plugins.d/mas.sh | 2 +- plugins.d/nodejs.sh | 2 +- plugins.d/perl.sh | 2 +- plugins.d/pip.sh | 2 +- plugins.d/pipx.sh | 4 +-- plugins.d/wp.sh | 2 ++ 10 files changed, 82 insertions(+), 20 deletions(-) diff --git a/kymsu2.sh b/kymsu2.sh index 63e0c0c..e46b4a2 100755 --- a/kymsu2.sh +++ b/kymsu2.sh @@ -1,6 +1,16 @@ #!/usr/bin/env bash -if [[ "$1" == "-h" || "$1" == "--help" ]]; then +italic="\033[3m" +underline="\033[4m" +ita_under="\033[3;4m" +bgd="\033[1;4;31m" +red="\033[1;31m" +bold="\033[1m" +bold_ita="\033[1;3m" +box="\033[1;41m" +reset="\033[0m" + +function showHelp() { echo -e "\033[93m\033[1maltKymsu\033[0m" echo "" echo "alt Keep Your macOs Stuff Updated" @@ -9,25 +19,59 @@ if [[ "$1" == "-h" || "$1" == "--help" ]]; then echo "USAGE: kymsu2" echo echo "Commandes: " - echo " -h, --help display this help" - echo " --nodistract no distract mode (no user interaction)" - echo " --cleanup removing any older versions of installed formulae and clearing old downloads from the Homebrew download-cache" - echo " --npm_cleanup cleaning npm cache" - echo " --all run all scripts (by default, all except those start by _)" + echo " -h, --help display this help" + echo " -n, --nodistract no distract mode (no user interaction)" + echo " -c, --cleanup removing any older versions of installed formulae and clearing old downloads from the Homebrew download-cache" + #echo " --npm_cleanup cleaning npm cache" + echo " -s $script run only the script given in argument" + echo " -a, --all run all scripts (by default, all except those start by _)" echo echo "Tips:" echo " -prefix the plugin with _ to ignore it" echo " -see Settings section on top of each plug-in" echo - exit 0 -fi +# exit 0 +} -echo "Please, grab a ☕️, KYMSU keep your working environment up to date!" +all_plugins=false +no_distract=false +brew_cleanup=false + +while getopts "hncs: a-:" opt +do + case $opt in + -) case "${OPTARG}" in + help) showHelp; exit;; + nodistract) no_distract=true;; + cleanup) brew_cleanup=true;; + all) all_plugins=true;; + *) + echo "Unknow option '--${OPTARG}'" >&2 + exit -1;; + esac;; + h) showHelp; exit;; + n) no_distract=true;; + c) brew_cleanup=true;; + s) one_script="${OPTARG}";; + a) all_plugins=true;; + *) + echo "Unknow option '-$opt'" >&2 + exit -1;; + esac +done + +#shift "$((OPTIND-1))" SCRIPTS_DIR=$HOME/.kymsu/plugins.d -[[ $@ =~ "--all" ]] && all_plugins=true || all_plugins=false -if [ "$all_plugins" = false ]; then +# -n : non vide +if [ -n "$one_script" ]; then + # Un seul script + list_plugins=$(find $SCRIPTS_DIR -maxdepth 1 -type f -name "*$one_script.sh" -a -perm +111) + [ -z "$list_plugins" ] && echo -e "❗️ No named plugin ${italic}$one_script${reset}" && exit -1 + +# [[ $@ =~ "--all" ]] && all_plugins=true || all_plugins=false +elif [ "$all_plugins" = false ]; then # Tous sauf commençant par _ (les fichiers commençant par '_' ne sont pas pris en compte) "_*.sh" list_plugins=$(find $SCRIPTS_DIR -maxdepth 1 -type f ! -name "_*" -a -name "*.sh" -a -perm +111 | sort) else @@ -37,7 +81,22 @@ fi cd "$SCRIPTS_DIR" +<