mirror of
https://github.com/scopatz/nanorc
synced 2025-06-20 13:40:07 +02:00
More Shellcheck corrections
This commit is contained in:
parent
2f6640c9c6
commit
2e3f607ef8
35
install.sh
35
install.sh
@ -28,7 +28,7 @@ G_IFS=" "
|
|||||||
# Global Variables
|
# Global Variables
|
||||||
G_VERSION="2019.10.17"
|
G_VERSION="2019.10.17"
|
||||||
G_DEPS="unzip sed"
|
G_DEPS="unzip sed"
|
||||||
G_FILE="~/.nanorc"
|
G_FILE="${HOME}/.nanorc"
|
||||||
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
G_REPO_MASTER="https://github.com/scopatz/nanorc/archive/master.zip"
|
||||||
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
G_REPO_RELEASE="https://github.com/scopatz/nanorc/archive/${G_VERSION}.zip"
|
||||||
unset G_LITE G_UNSTABLE G_VERBOSE G_DIR G_THEME
|
unset G_LITE G_UNSTABLE G_VERBOSE G_DIR G_THEME
|
||||||
@ -117,13 +117,15 @@ f_set_ifs(){
|
|||||||
# Sources: https://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash
|
# Sources: https://unix.stackexchange.com/questions/23111/what-is-the-eval-command-in-bash
|
||||||
f_set_variable(){
|
f_set_variable(){
|
||||||
varname=$1
|
varname=$1
|
||||||
|
varvalue=""
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Because 'sh' do not recognize indirect expansion "${!#}"
|
# Because 'sh' do not recognize indirect expansion "${!#}" like bash.
|
||||||
eval varvalue="$"$varname
|
# Alert! The backslash "\" is needed!
|
||||||
|
eval varvalue="\$${varname}"
|
||||||
|
|
||||||
if [ -z "${varvalue}" ]; then
|
if [ -z "${varvalue}" ]; then
|
||||||
eval "$varname=${@}"
|
eval "$varname=${*}"
|
||||||
else
|
else
|
||||||
echo "Error: ${varname} already set."
|
echo "Error: ${varname} already set."
|
||||||
usage
|
usage
|
||||||
@ -157,9 +159,13 @@ f_install(){
|
|||||||
begin="# BEGIN"
|
begin="# BEGIN"
|
||||||
end="# END"
|
end="# END"
|
||||||
theme="${G_DIR}/themes/${G_THEME}/"
|
theme="${G_DIR}/themes/${G_THEME}/"
|
||||||
cd ~
|
|
||||||
|
|
||||||
mkdir -p $G_DIR
|
if [ ! cd "$HOME" ]; then
|
||||||
|
echo "Error: Cannot open or access ${HOME} directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$G_DIR"
|
||||||
|
|
||||||
if [ ! -d "$G_DIR" ]; then
|
if [ ! -d "$G_DIR" ]; then
|
||||||
echo "Error: ${G_DIR} is not a directory or cannot be accessed or created."
|
echo "Error: ${G_DIR} is not a directory or cannot be accessed or created."
|
||||||
@ -176,10 +182,10 @@ f_install(){
|
|||||||
rm $temp
|
rm $temp
|
||||||
|
|
||||||
if [ "$G_UNSTABLE" = true ]; then
|
if [ "$G_UNSTABLE" = true ]; then
|
||||||
mv "nanorc-master/*" $G_DIR
|
mv "nanorc-master/*" "$G_DIR"
|
||||||
rm -rf "nanorc-master"
|
rm -rf "nanorc-master"
|
||||||
else
|
else
|
||||||
mv "nanorc-${G_VERSION}" $G_DIR
|
mv "nanorc-${G_VERSION}" "$G_DIR"
|
||||||
rm -rf "nanorc-${G_VERSION}"
|
rm -rf "nanorc-${G_VERSION}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -190,9 +196,10 @@ f_install(){
|
|||||||
|
|
||||||
touch "$G_FILE"
|
touch "$G_FILE"
|
||||||
|
|
||||||
echo "$begin" >> $G_FILE
|
{ echo "$begin";
|
||||||
echo "" >> $G_FILE
|
echo "";
|
||||||
echo "$end" >> $G_FILE
|
echo "$end";
|
||||||
|
} >> $G_FILE
|
||||||
|
|
||||||
if [ "$G_LITE" = true ]; then
|
if [ "$G_LITE" = true ]; then
|
||||||
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
sed -n -i.bkp '/'"$begin"'/,/'"$end"'/ {
|
||||||
@ -234,10 +241,10 @@ f_check_deps && exit 1
|
|||||||
# Getopts: https://www.shellscript.sh/tips/getopts/
|
# Getopts: https://www.shellscript.sh/tips/getopts/
|
||||||
while getopts "d:hlt:uvw" c; do
|
while getopts "d:hlt:uvw" c; do
|
||||||
case $c in
|
case $c in
|
||||||
d) f_set_variable G_DIR $OPTARG ;;
|
d) f_set_variable G_DIR "$OPTARG" ;;
|
||||||
h) f_menu_usage ;;
|
h) f_menu_usage ;;
|
||||||
l) f_set_variable G_LITE true ;;
|
l) f_set_variable G_LITE true ;;
|
||||||
t) f_set_variable G_THEME $OPTARG ;;
|
t) f_set_variable G_THEME "$OPTARG" ;;
|
||||||
u) f_set_variable G_UNSTABLE true ;;
|
u) f_set_variable G_UNSTABLE true ;;
|
||||||
v) f_menu_version ;;
|
v) f_menu_version ;;
|
||||||
w) f_set_variable G_VERBOSE true ;;
|
w) f_set_variable G_VERBOSE true ;;
|
||||||
@ -246,7 +253,7 @@ while getopts "d:hlt:uvw" c; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Set defaults if there is not.
|
# Set defaults if there is not.
|
||||||
[ -z "$G_DIR" ] && G_DIR="~/.nano/nanorc/"
|
[ -z "$G_DIR" ] && G_DIR="${HOME}/.nano/nanorc/"
|
||||||
[ -z "$G_THEME" ] && G_THEME="scopatz"
|
[ -z "$G_THEME" ] && G_THEME="scopatz"
|
||||||
|
|
||||||
# Set verbose
|
# Set verbose
|
||||||
|
Loading…
x
Reference in New Issue
Block a user