-
Notifications
You must be signed in to change notification settings - Fork 1
/
kymsu2.sh
executable file
·107 lines (91 loc) · 2.95 KB
/
kymsu2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
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"
echo "a fork from kymsu https://github.com/welcoMattic/kymsu"
echo
echo "USAGE: kymsu2"
echo
echo "Commandes: "
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
}
all_plugins=false
no_distract=false
brew_cleanup=false
SCRIPTS_DIR=$HOME/.kymsu/plugins.d
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))"
# -n : non vide
if [ -n "$one_script" ]; then
# Un seul script
#list_plugins=$(find $SCRIPTS_DIR -maxdepth 1 -type f -name "*$one_script" -a -perm +111)
list_plugins=$(find $SCRIPTS_DIR -maxdepth 1 -type f -name "$one_script" -o -name "_$one_script" -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)
[ -z "$list_plugins" ] && echo -e "❗️ No plugin in ${italic}$SCRIPTS_DIR${reset}" && exit -1
else
# Tous (-a = ET; -perm +111 = exec)
list_plugins=$(find $SCRIPTS_DIR -maxdepth 1 -type f -name "*.sh" -a -perm +111 | sort)
[ -z "$list_plugins" ] && echo -e "❗️ No plugin in ${italic}$SCRIPTS_DIR${reset}" && exit -1
fi
cd "$SCRIPTS_DIR"
<<COMMENT
echo "$list_plugins"
echo "all args: $@"
echo ""
echo "script: $one_script"
echo ""
COMMENT
echo "Please, grab a ☕️, KYMSU keep your working environment up to date!"
echo ""
for script in $list_plugins; do
# le $@ permet de passer à chaque script les arguments passés à *ce* script
$script $@
#echo "$script"
done
shift "$((OPTIND-1))"