Skip to content

Instantly share code, notes, and snippets.

Last active September 28, 2022 09:26
What would you like to do?
A shell script to create an SBT project directory structure
# Name: sbtmkdirs
# Version: 1.5
# Purpose: Create an SBT project directory structure with a few simple options.
# Author: Alvin Alexander,
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
declare -r TRUE=0
declare -r FALSE=1
# takes a string and returns true if it seems to represent "yes"
function isYes() {
local x=$1
[ $x = "y" ] && echo $TRUE; return
[ $x = "Y" ] && echo $TRUE; return
[ $x = "yes" ] && echo $TRUE; return
echo $FALSE
echo "This script creates an SBT project directory beneath the current directory."
while [ $TRUE ]; do
echo ""
read -p "Directory/Project Name (MyFirstProject): " directoryName
read -p "Create .gitignore File? (Y/n): " createGitignore
read -p "Create File? (Y/n): " createReadme
echo ""
echo "-----------------------------------------------"
echo "Directory/Project Name: $directoryName"
echo "Create .gitignore File?: $createGitignore"
echo "Create File?: $createReadme"
echo "-----------------------------------------------"
read -p "Create Project? (Y/n): " createProject
[ "$(isYes $createProject)" = "$TRUE" ] && break
mkdir -p ${directoryName}/src/{main,test}/{java,resources,scala}
mkdir ${directoryName}/lib ${directoryName}/project ${directoryName}/target
# optional
#mkdir -p ${directoryName}/src/main/config
#mkdir -p ${directoryName}/src/{main,test}/{filters,assembly}
#mkdir -p ${directoryName}/src/site
# create an initial build.sbt file
echo "name := \"$directoryName\"
version := \"1.0\"
scalaVersion := \"2.12.8\"
libraryDependencies ++= Seq(
\"org.scalatest\" %% \"scalatest\" % \"3.0.5\" % \"test\"
// see for scalacOptions descriptions
scalacOptions ++= Seq(
\"-deprecation\", //emit warning and location for usages of deprecated APIs
\"-unchecked\", //enable additional warnings where generated code depends on assumptions
\"-explaintypes\", //explain type errors in more detail
\"-Ywarn-dead-code\", //warn when dead code is identified
\"-Xfatal-warnings\" //fail the compilation if there are any warnings
" > ${directoryName}/build.sbt
# create .gitignore, if desired
if [ "$(isYes $createGitignore)" = "$TRUE" ]; then
echo "bin/
.idea" > ${directoryName}/.gitignore
# create, if desired
if [ "$(isYes $createReadme)" = "$TRUE" ]; then
touch ${directoryName}/
echo ""
echo "Project created. See the following URL for build.sbt examples:"
echo ""
Copy link

alvinj commented Dec 27, 2018

See for information on how to use this script with Scala and SBT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment