Skip to content

Instantly share code, notes, and snippets.

@rkaneko
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkaneko/6c849ef2a00262e632e6 to your computer and use it in GitHub Desktop.
Save rkaneko/6c849ef2a00262e632e6 to your computer and use it in GitHub Desktop.
Shell script for cpp-template. Pls see https://github.com/rkaneko/cpp-template .
#!/bin/bash
### Shell script for https://github.com/rkaneko/cpp-template .
###
### @author rkaneko
### @createAt 2014/07/12
# see if arg exists or not.
# arg0: some arg
existArg1()
{
local EXIST_ARG1=false
# See if $1's length greater than 0 .
if [ $1 ]
then
local EXIST_ARG1=true
fi
echo ${EXIST_ARG1}
}
# see if some command exists in system or not.
# arg0: some command
existCmd()
{
if [ `existArg1 $1` = false ]
then
echo false
return
fi
local SOME_CMD=$1
local PATH_TO_CMD=`which ${SOME_CMD}`
local IS_EXIST=false
if [ ${#PATH_TO_CMD} -ge ${#SOME_CMD} ]
then
local IS_EXIST=true
fi
echo ${IS_EXIST}
}
# print usage of cpptemp.
printHelp()
{
cat <<_EOT_
Usage: cpptemplate [-h]
ex) $ cpptemplate
If you want to see cpptemp's help,
$ cpptemplate -h
_EOT_
return
}
# If user add option '-h', print help.
if [ "$1" = '-h' ]
then
printHelp
exit 0
fi
if [ `existCmd 'git'` = false ]
then
cat <<_EOT_
error:
cpptemp depends on 'git'.
You should install Git.
_EOT_
exit 1
fi
# create cpp-template interactively
echo 'Input your project name.'
read -p \>\ PROJECT_NAME
if [ `existArg1 ${PROJECT_NAME}` = false ]
then
# default app name is helloworld
PROJECT_NAME='helloworld'
fi
_WORKING_DIR=`pwd`
# git clone
git clone https://github.com/rkaneko/cpp-template.git ${_WORKING_DIR}/${PROJECT_NAME}
cd ${_WORKING_DIR}/${PROJECT_NAME}
# invoke cpp-template/script/init.sh
${_WORKING_DIR}/${PROJECT_NAME}/script/init.sh ${PROJECT_NAME}
echo 'Created '${PROJECT_NAME} '!'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment