Skip to content

Instantly share code, notes, and snippets.

@albang
Last active January 3, 2016 12:29
Show Gist options
  • Select an option

  • Save albang/8463211 to your computer and use it in GitHub Desktop.

Select an option

Save albang/8463211 to your computer and use it in GitHub Desktop.
bibliothèque pour script bash evolué (ou pas)
#!/bin/bash
#Ecris par Alban, inspiré par riad
#### Changelog ####
#0.1 :Initial release
#Ce fichier contient plusieurs fonctions :
#ecrire en couleur
#
#possiblilités :
# echorouge
# echovert
# echobleu
# echoorange
# echocyan
# echoviolet
#yesorno
#
#Cette fonction permet de demander la confirmation
#elle retourne 0 si oui et 1 si non
#result
#Cette fonction test le code retourne de la derniere commande exécutée
#si retour 0 elle affiche ok en vert
#sinon elle affiche fail
#okneeded
#meme fonction que result avec un exit en cas de fail
if [[ $TERM && $TERM != "dumb" ]]
then
COLOR_RED="\\033[1;31m"
COLOR_GREEN="\\033[1;32m"
COLOR_ORANGE="\\033[1;33m"
COLOR_BLUE="\\033[1;34m"
COLOR_VIOLET="\\033[1;35m"
COLOR_CYAN="\\033[1;36m"
COLOR_SEC="\\033[1;30m"
NORMAL="\\033[0;39m"
fi
reset_color() {
if [[ $TERM && $TERM != "dumb" ]]
then
echo -ne $NORMAL""
#/usr/bin/tput sgr0;
fi
}
echorouge() {
echo -en $COLOR_RED"$1"
reset_color
}
echovert() {
echo -en $COLOR_GREEN"$1"
reset_color
}
echobleu() {
echo -en $COLOR_BLUE"$1"
reset_color
}
echoorange() {
echo -en $COLOR_ORANGE"$1"
reset_color
}
echocyan() {
echo -en $COLOR_CYAN"$1"
reset_color
}
echoviolet() {
echo -en $COLOR_VIOLET"$1"
reset_color
}
echosec(){
echo -en $COLOR_SEC"$1"
}
yesorno() {
echo "Validez vous ce choix ?"
echo "(Y)es or (N)o"
read yesorno
while [[ $yesorno != "Y" && $yesorno != "N" ]]
do
echo "Validez vous ce choix ?"
echo "(Y/N)"
read yesorno
done
if [ "$yesorno" == "N" ]
then
return 1
else
return 0
fi
}
result() {
if [ $? -eq 0 ]
then
echovert "OK\n"
return 0
else
echorouge "FAIL\n"
return 1
fi
}
okneeded() {
if [ $? -eq 0 ]
then
echovert "OK\n"
return 0;
else
echorouge "FAIL\n"
exit 1
fi
}
customexit() {
echoorange "Message d'erreur :"; echorouge "$1"
exit 1;
}
siouisinon() {
if [ $? -eq 0 ]
then
$1
else
$2
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment