Better IFS and parameters

This commit is contained in:
Tiago Almeida 2019-11-03 23:22:28 +00:00
parent e1bba94e7b
commit 5125a77303

View File

@ -19,12 +19,13 @@
# Ativate or not the erros (1=activated) # Ativate or not the erros (1=activated)
OPTERR=1 OPTERR=1
# Separator (useful for simulate arrays) # Separator (useful for simulate arrays)
IFS=" " G_IFS=" "
# Global Variables # Global Variables
G_VERSION="1.0.0" G_VERSION="1.0.0"
G_NANORC_FILE="~/.nanorc"
G_DEPS="unzip sed wget" G_DEPS="unzip sed wget"
G_LITE=false
G_FILE="~/.nanorc"
# Exit Values Help # Exit Values Help
# 0 - OK # 0 - OK
@ -39,11 +40,13 @@ f_menu_usage(){
echo "IMPROVED NANO SYNTAX HIGHLIGHTING FILES" echo "IMPROVED NANO SYNTAX HIGHLIGHTING FILES"
echo "Get nano editor better to use and see." echo "Get nano editor better to use and see."
echo echo
echo "-l Activate lite installation." echo "-l Activate lite installation."
echo "-v Show version, license and other info." echo " We will take account your existing .nanorc files."
echo "-h Show help or usage." echo "-v Show version, license and other info."
echo "-f FILE Other file instead of the default .nanorc file." echo "-h Show help or usage."
echo "-f FILE"
echo " Other file instead of the default .nanorc file."
exit 2 exit 2
} }
@ -58,6 +61,8 @@ f_menu_version(){
echo "There is NO WARRANTY, to the extent permitted by law." echo "There is NO WARRANTY, to the extent permitted by law."
echo echo
echo "Written by Anthony Scopatz and others." echo "Written by Anthony Scopatz and others."
echo
echo "For bugs report, please fill an issue at https://github.com/scopatz/nanorc"
exit 0 exit 0
} }
@ -84,6 +89,13 @@ f_check_deps(){
fi fi
} }
# Set IFS
f_set_ifs(){
temp=$IFS
IFS=$G_IFS
G_IFS=temp
}
_fetch_sources(){ _fetch_sources(){
wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip
mkdir -p ~/.nano/ mkdir -p ~/.nano/
@ -111,32 +123,38 @@ _update_nanorc_lite(){
} }
# corewct the get ifs # check parameters with set variable
# check parameters with getopts # made the script more or less verbose
# help version license+info output bugs report
# init main # init main
# get the git # get the git
# updat/create the nanorc # updat/create the nanorc
# ============================
#
# MAIN / Init of script
#
# =============================
# Main / Init of script f_set_ifs
f_check_deps && exit 2
f_check_deps while getopts "lf:vh?" c
case $c in
l) G_LITE=true;;
f) G_FILE=$OPTARG;;
v) f_menu_version ;;
h|?|*) f_menu_usage ;;
esac
done
case "$1" in _fetch_sources
-l|--lite)
UPDATE_LITE=1;;
-h|--help)
echo "Install script for nanorc syntax highlights"
echo "Call with -l or --lite to update .nanorc with secondary precedence to existing .nanorc includes"
;;
esac
_fetch_sources; if [ $G_LITE ];
if [ $UPDATE_LITE ];
then then
_update_nanorc_lite _update_nanorc_lite
else else
_update_nanorc _update_nanorc
fi fi
f_set_ifs