For the first time ever I decided to write a bash script. It works fine, but I'm feeling that I didn't write the most efficient code in order for future extension of the script. I also don't really get a good feeling on the look of the code. Any suggestions on how to improve the script?
Purpose of the script: To pull a vim configuration located on github and then copy the files to the home directory and create some directories needed by the vim configuration.
dirs=( "~/.vim/undo" "~/.vim/swap" "~/.vim/backup" )
function error_exit
{
printf '[failed\n]'
exit 1
}
printf ' vim_config by Roel0 \n'
printf ' version 1.0 \n'
printf 'Updating vim configuration ... '
if !(git pull > /dev/null;) then
error_exit
fi
printf '[OK]\n'
printf 'Installing vim configuration ... '
if !(cp -r ./.vim* ~/) then
error_exit
fi
printf '[OK]\n'
printf 'Creating configured directories ... '
for i in "${dirs[@]}"
do
if !(mkdir -p $i) then
error_exit
fi
done
printf '[OK]\n'
!(cmd)
is valid syntax. And since~
is not expanded within double-quotes, I doubt the script will do what you want. Have you tested this well? Are you sure it works? – janos♦ Jan 27 at 13:19