mirror of
https://github.com/scopatz/nanorc
synced 2025-06-20 13:40:07 +02:00
Enhance the fetch sources function
This commit is contained in:
parent
7d3fc57068
commit
49d4623031
99
install.sh
99
install.sh
@ -16,7 +16,6 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# Help:
|
# Help:
|
||||||
# Getopts: https://www.shellscript.sh/tips/getopts/
|
|
||||||
# Sed: http://www.grymoire.com/Unix/Sed.html
|
# Sed: http://www.grymoire.com/Unix/Sed.html
|
||||||
|
|
||||||
# Bash Variables
|
# Bash Variables
|
||||||
@ -26,32 +25,35 @@ OPTERR=1
|
|||||||
G_IFS=" "
|
G_IFS=" "
|
||||||
|
|
||||||
# Global Variables
|
# Global Variables
|
||||||
G_VERSION="1.0.0"
|
G_VERSION="2019.10.17"
|
||||||
G_DEPS="unzip sed wget"
|
G_DEPS="unzip sed"
|
||||||
G_LITE=false
|
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
||||||
G_FILE="~/.nanorc"
|
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
||||||
|
unset G_LITE G_FILE G_VERBOSE G_UNSTABLE
|
||||||
|
|
||||||
# Exit Values Help
|
# Exit Values Help
|
||||||
# 0 - OK
|
# 0 - OK
|
||||||
# 1 - Small problem
|
# 1 - Big problem
|
||||||
# 2 - Big problem
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
# Show the usage/help
|
# Show the usage/help
|
||||||
f_menu_usage(){
|
f_menu_usage(){
|
||||||
echo "Usage: $0 [ -l|-v|-h ] [ -f FILE ]"
|
echo "Usage: $0 [ -h | -l | -t | -u | -v ] [ -f FILE ]"
|
||||||
|
echo
|
||||||
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 " We will take account your existing .nanorc files."
|
|
||||||
echo "-v Show version, license and other info."
|
|
||||||
echo "-h Show help or usage."
|
echo "-h Show help or usage."
|
||||||
|
echo "-l Activate lite installation."
|
||||||
|
echo " We will take account your existing .nanorc files."
|
||||||
|
echo "-t Turn the script more verbose, often to tests."
|
||||||
|
echo "-u Use the unstable branch."
|
||||||
|
echo "-v Show version, license and other info."
|
||||||
echo "-f FILE"
|
echo "-f FILE"
|
||||||
echo " The path of other file instead of the default .nanorc file."
|
echo " The path of other file instead of the default .nanorc file."
|
||||||
|
|
||||||
exit 2
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Show version, license and other file.
|
# Show version, license and other file.
|
||||||
@ -100,12 +102,45 @@ f_set_ifs(){
|
|||||||
G_IFS=temp
|
G_IFS=temp
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetch_sources(){
|
# Set Variable
|
||||||
wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip
|
# Receives two parameters:
|
||||||
|
# 1. the variable name
|
||||||
|
# 2. a value
|
||||||
|
# Sources: https://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash
|
||||||
|
f_set_variable(){
|
||||||
|
varname=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
# Because 'sh' do not recognize indirect expansion "${!#}"
|
||||||
|
eval varvalue="$"$varname
|
||||||
|
|
||||||
|
if [ -z "${varvalue}" ]; then
|
||||||
|
eval "$varname=${@}"
|
||||||
|
else
|
||||||
|
echo "Error: ${varname} already set"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fetch Sources
|
||||||
|
# todo: check the directory/file before call this function
|
||||||
|
# todo: add a no directory or other nam
|
||||||
|
# todp: rename to install
|
||||||
|
f_fetch_sources()
|
||||||
|
temp="temp.zip"
|
||||||
|
cd ~
|
||||||
|
|
||||||
|
if [ "$G_UNSTABLE" = true ]; then
|
||||||
|
curl -L -o $temp $G_REPO_MASTER
|
||||||
|
else
|
||||||
|
curl -L -o $temp $G_REPO_RELEASE
|
||||||
|
fi
|
||||||
|
|
||||||
|
unzip -u -d $G_DIR $temp
|
||||||
|
|
||||||
mkdir -p ~/.nano/
|
mkdir -p ~/.nano/
|
||||||
|
|
||||||
cd ~/.nano/ || exit
|
|
||||||
unzip -o "/tmp/nanorc.zip"
|
|
||||||
mv nanorc-master/* ./
|
mv nanorc-master/* ./
|
||||||
rm -rf nanorc-master
|
rm -rf nanorc-master
|
||||||
rm /tmp/nanorc.zip
|
rm /tmp/nanorc.zip
|
||||||
@ -127,10 +162,6 @@ _update_nanorc_lite(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# check parameters with set variable
|
|
||||||
# made the script more or less verbose
|
|
||||||
|
|
||||||
# init main
|
|
||||||
# get the git
|
# get the git
|
||||||
# updat/create the nanorc
|
# updat/create the nanorc
|
||||||
|
|
||||||
@ -140,19 +171,33 @@ _update_nanorc_lite(){
|
|||||||
#
|
#
|
||||||
# =============================
|
# =============================
|
||||||
|
|
||||||
|
# Pre-check
|
||||||
f_set_ifs
|
f_set_ifs
|
||||||
f_check_deps && exit 2
|
f_check_deps && exit 1
|
||||||
|
|
||||||
while getopts "lf:vh?" c
|
# Menu
|
||||||
|
# Getopts: https://www.shellscript.sh/tips/getopts/
|
||||||
|
while getopts "hltvf:" c
|
||||||
case $c in
|
case $c in
|
||||||
l) G_LITE=true;;
|
h) f_menu_usage ;;
|
||||||
f) G_FILE=$OPTARG;;
|
l) f_set_variable G_LITE true ;;
|
||||||
|
t) f_set_variable G_VERBOSE true ;;
|
||||||
|
u) f_set_variable G_UNSTABLE true
|
||||||
v) f_menu_version ;;
|
v) f_menu_version ;;
|
||||||
h|?|*) f_menu_usage ;;
|
f) f_set_variable G_FILE $OPTARG ;;
|
||||||
|
*) f_menu_usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
_fetch_sources
|
# Check the file
|
||||||
|
[ -z "$G_FILE" ] && G_FILE="~/.nanorc"
|
||||||
|
|
||||||
|
# Set verbose
|
||||||
|
if [ "$G_VERBOSE" = true ]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
|
f_fetch_sources
|
||||||
|
|
||||||
if [ $G_LITE ];
|
if [ $G_LITE ];
|
||||||
then
|
then
|
||||||
@ -161,4 +206,6 @@ else
|
|||||||
_update_nanorc
|
_update_nanorc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Post-check
|
||||||
f_set_ifs
|
f_set_ifs
|
||||||
|
exit 0
|
||||||
|
3
todo.md
3
todo.md
@ -11,4 +11,5 @@
|
|||||||
4. Make the install file the oficial installaton and update it accordingly.
|
4. Make the install file the oficial installaton and update it accordingly.
|
||||||
|
|
||||||
0. make the installation with more plesant wait
|
0. make the installation with more plesant wait
|
||||||
0. may be begin with version system 1.0.0 ...
|
0. may be begin with version system 1.0.0
|
||||||
|
0. make a function for error output/echo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user