Skip to content

Instantly share code, notes, and snippets.

@paulp
Created January 2, 2017 17:57
Show Gist options
  • Save paulp/ba9bd0b5808a808c67cbd2bb9db08005 to your computer and use it in GitHub Desktop.
Save paulp/ba9bd0b5808a808c67cbd2bb9db08005 to your computer and use it in GitHub Desktop.
a less messy sbt new
#!/usr/bin/env bash
#
# Intercepting the output of 'sbt new' directly fails
# because it asks interactive questions so we can't process
# line by line. An apparent OSX-specific bug in egrep
# fails on lookbehind clauses so we use ag. Capturing
# the interactive output with script succeeds, but script
# uses \r\n to terminate lines so we can't match the
# filename with '.*' or we get
#
# mv: rename ./proj\r to /tmp/proj\r: No such file or directory
#
# Remember this entire wrapper only exists because 'sbt new'
# insensibly wants to spew build files into your current directory.
set -euo pipefail
initial="$(pwd)"
scratch="$(mktemp -dt sbt-new)"
cd $scratch
script -q out.txt sbt -Dsbt.log.noformat=true new "$@"
proj="$( ag --nocolor -o '(?<=Template applied in )[^\r\n]*' out.txt )"
mv -i "$proj" "$initial"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment